我試圖獲取從我的java代碼列的最大數據集,但我得到從結果中獲取數據在Java
是如下圖所示
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/testdb123","root","root");
LOGGER.info("connected to the database");
Statement stmt0 = conn.createStatement();
String qr= "INSERT INTO stumarks " + "VALUES ("+null+","+marks+")";
Statement stmt1 = conn.createStatement();
stmt1.executeUpdate(qr);
String countQuery = "select MAX('seqNum') as count1 from stumarks";
ResultSet res = stmt0.executeQuery(countQuery);
LOGGER.info("result set success!!");
int num = res.getInt("count1");``
System.out.println(num);
我的代碼的結果,錯誤設定
作爲大將風範的意見,這是更好的使用參數化查詢比連接字符串進行查詢(更快,更清晰,不易出錯),和常量,如' count1'通常應該移入常量變量('public static final'),而不是嵌入到代碼中。 – chrylis