我的也是同样的报错
public void getData() throws ClassNotFoundException, SQLException {
ResultSet rs = conn.createStatement().executeQuery("select * from t_article");
//try{rs.last();}catch(SQLException e){System.out.println("int:"+rs.getRow()+" "+e.toString());}; //移到最后一行
rs.last();
if(rs.getRow()>0) { //获取当前rs位置(获取记录数量)
rs.beforeFirst(); //移到初始位置
while(rs.next()) {
System.out.println( rs.getInt(1)+ " " + rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4) + " " + rs.getDate(5));
}
}else {
System.out.println("没有数据");
}
rs.close();
}
----------------------------------------------------OUTPUT---------------------------------------------------------
Exception in thread "main" java.sql.SQLException: Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.result.ResultSetImpl.last(ResultSetImpl.java:1729)
at SQLData.resultset(SQLData.java:85)
at SQLData.getData(SQLData.java:81)
at SQLData.main(SQLData.java:19)
Process finished with exit code 1