mysql中关于分页查询的输出问题!
程序员文章站
2022-05-08 10:17:58
...
mysql分页sql
String sql = "select * from emp order by empno limit ?,?";
prepareStatement stmt = con.prepareStatement(sql);
stmt.setInt(1, begin);
stmt.setInt(2, end);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
System.out.println(rs.getInt("empno") + ","
+ rs.getString("ename") + ","
+ rs.getDouble("sal") + "," + rs.getDate("hiredate"));}
一直对rs.getxxx()的用法比较模糊,求介绍下用法 返回的结果集rs是不是既可以按列名rs.getxxx("xxx")也可以按rs.getxxx(1)这样读取啊? 另外上面的代码中输出语句里面我可以不可以写成 while (rs.next()) { System.out.println(rs.getInt(1) + "," + rs.getString(2) + "," + rs.getDouble(3) + "," + rs.getDate(4));}