我试图获取从我的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