jdbc 连接mysql 首次成功,之后连接就报错

WBOY
發布: 2016-06-06 09:41:59
原創
1380 人瀏覽過

mysqljdbc

在系统中使用jdbc 连接mysql, 首次成功,之后连接就报错,驱动用的是mysql-connector-java-5.1.15-bin.jar
连接代码

<code> Connection conn = null;        Statement stat = null;        ResultSet rs = null;        String url = "jdbc:mysql://*********:3306/*******?useUnicode=true&characterEncoding=GBK";        String sql = null;        String tableName = "***";        List<clockbo> clock = new ArrayList<clockbo>();            sql = "select * from "                    + tableName                    + " where timevalue between '"                    + startTime                    + "' and '" + endTime + "' and doorName='" + doorName.substring(2) + "'";            System.out.println(sql);            Class.forName("com.mysql.jdbc.Driver");            conn = DriverManager.getConnection(url, "root", "****");            stat = conn.createStatement();            rs = stat.executeQuery(sql);            while (rs.next()) {                ClockBO bo = new ClockBO();                ClockPKBO pkbo = new ClockPKBO();                pkbo.setCardNo1(rs.getString(1));                pkbo.setCardNo2(rs.getString(2));                pkbo.setTimeValue(ft.format(rs.getTimestamp(6)));                bo.setPersonNo(rs.getString(3));                bo.setPersonName(rs.getString(4));                bo.setDepartment(rs.getString(5));                bo.setCtlIp(rs.getString(7));                bo.setDoorNo(rs.getString(8));                bo.setDoorName(rs.getString(9));                bo.setStateId(rs.getString(10));                bo.setRptState(rs.getString(11));                bo.setStateStr(rs.getString(12));                bo.setClockPK(pkbo);                clock.add(bo);                System.out.println(rs.getString(4));                System.out.println(bo.toString());            }        } catch (Exception e) {            e.printStackTrace();        }finally{            try{            if(null!=rs){                rs.close();            }            if(null!=stat){                stat.close();            }            if(null!=conn){                conn.commit();            conn.close();            }            }catch(SQLException e){                e.printStackTrace();            }        }</clockbo></clockbo></code>
登入後複製

首次连接可以查出数据,再次调用就在连接的时候就抛出异常了,异常信息如下

java.sql.SQLException: ResultSet is from UPDATE. No Data.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6999)
at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:4184)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3585)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2534)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2304)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)

<code>为什么会出现这种情况呢?</code>
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板