Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-06 09:41:59
Original
1381 people have browsed it

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>
Copy after login

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

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template