public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver") ;
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/smss" , "root" , "mysql") ;
PreparedStatement pstate = conn.prepareStatement("select * from sms_user_sending where channel=15") ;
ResultSet rs = pstate.executeQuery() ;
while (rs.next()) {
System.out.println(rs.getInt(1)) ;
}
rs.close() ;
pstate.close() ;
conn.close() ;
}
}
此段代码在运行的时候如果选择run模式,没有任何问题,但是用Eclipse选择Debug模式进行单步调试运行,则会报异常信息:
Exception in thread "main" java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:692)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2372)
at com.test.PreparedStatementTest.main(PreparedStatementTest.java:12)