• 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的总列数。

  • 相关阅读:
    ABP 菜单 修改
    C# 过滤器
    RabbitMQ框架构建系列(三)——Net实现RabbitMQ之Producer
    RabbitMQ系列(二)RabbitMQ基础介绍
    RabbitMQ系列(一)AMPQ协议
    MVC 解读WebConfig
    MVC过滤器特性
    asp.net中使用JQueryEasyUI
    asp.net请求到响应的整个过程
    Redis的下载安装部署(Windows)
  • 原文地址:https://www.cnblogs.com/w-wfy/p/5295551.html
Copyright © 2020-2023  润新知