我想编写从表中给出最大 id 的代码,但它会抛出错误。
代码:
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("XXXXX", "XXXX", "XXX");
Statement st2 = con.createStatement();
ResultSet idMax = st2.executeQuery("select nvl(max(work_id),0) from workdetails");
int id2 = idMax.getInt(0); // throw error: Invalid column index
System.out.println(id2);
// ****************************
int id2 = idMax.getInt("work_id");
System.out.println(id2); // throw error: ResultSet.next was not called