时间:2021-07-01 10:21:17 帮助过:32人阅读
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));}