专修虚拟机
2015-12-05 11:58
采纳率: 18.8%
浏览 1.4k

mysql中关于分页查询的输出问题!

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));}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题