• ResultSet


    在Java中,获得ResultSet的总行数的方法有以下几种。 
    第一种:利用ResultSet的getRow方法来获得ResultSet的总行数 

    Java代码
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); 
    ResultSet rset = stmt.executeQuery("select * from yourTableName"); 
    rset.last(); 
    int rowCount = rset.getRow(); //获得ResultSet的总行数 
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet rset = stmt.executeQuery("select * from yourTableName"); rset.last(); int rowCount = rset.getRow(); //获得ResultSet的总行数第二种:利用循环ResultSet的元素来获得ResultSet的总行数 

    Java代码
    ResultSet rset = stmt.executeQuery("select * from yourTableName"); 
    int rowCount = 0; 
    while(rset.next()) { 
    rowCount++; 

    ResultSet rset = stmt.executeQuery("select * from yourTableName"); int rowCount = 0; while(rset.next()) { rowCount++; }rowCount就是ResultSet的总行数。 
    第三种:利用sql语句中的count函数获得ResultSet的总行数 

    Java代码
    ResultSet rset = stmt.executeQuery("select count(*) totalCount from yourTableName"); 
    int rowCount = 0; 
    if(rset.next()) { 
    rowCount=rset .getInt("totalCount "); 

    ResultSet rset = stmt.executeQuery("select count(*) totalCount from yourTableName"); int rowCount = 0; if(rset.next()) { rowCount=rset .getInt("totalCount "); }rowCount就是ResultSet的总行数。 

    • Java中获得ResultSet的总列数是非常简单事情,因为Java中ResultSet提供了ResultSetMetaData工具类,ResultSetMetaData 是ResultSet的元数据的集合说明。 
    java获得ResultSet总列数的代码如下: 

    Java代码
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); 
    ResultSet rset = stmt.executeQuery("select * from yourtable"); 
    ResultSetMetaData rsmd = rset.getMetaData() ; 
    int columnCount = rsmd.getColumnCount(); 
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet rset = stmt.executeQuery("select * from yourtable"); ResultSetMetaData rsmd = rset.getMetaData() ; int columnCount = rsmd.getColumnCount();columnCount 就是ResultSet的总列数。

  • 相关阅读:
    vip视频播放
    一行Python代码画心型
    使用赫夫曼编码压缩数据
    动态规划与贪婪算法学习笔记
    boost 编写finger服务
    磁盘保护原理简介
    知乎上的一道题目 如何判断某个二进制数如是否存在两位1中间有包含0的情况?
    <Linux多线程服务端编程>学习记录
    Debian8 下面 muduo库编译与使用
    无盘工作站原理分析
  • 原文地址:https://www.cnblogs.com/w-wfy/p/5295551.html
Copyright © 2020-2023  润新知