1、Exception
java.sql.SQLException: Before start of result set
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.result.ResultSetImpl.checkRowPos(ResultSetImpl.java:484)
at com.mysql.cj.jdbc.result.ResultSetImpl.getObject(ResultSetImpl.java:1283)
at com.mysql.cj.jdbc.result.ResultSetImpl.getInt(ResultSetImpl.java:786)
at com.mysql.cj.jdbc.result.ResultSetImpl.getInt(ResultSetImpl.java:807)
2、ResultSet的next方法
返回单个对象的情况,我原以为可以直接拿rs的数据,结果一直报错,没发现错哪
然后我输出rs.next()发现也是true,说明是获取到结果集了
然后我想起了一起get前都要加next,然后试出来了
3、next原理:
- ResultSet对象获取结果集后位于第0条,没有数据
- 通过next移到下一条,如果没有返回false,有的话移到下一条数据并返回true
- 所有如果没有next的话是移动不到有数据的那一条的
- 希望世界没有bug