此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【XINGDONGLI】截止到2008-07-29 16:27:18的历史汇总数据(不包括此帖):
发帖的总数量:5                        发帖的总分数:40                       每贴平均分数:8                        
回帖的总数量:4                        得分贴总数量:0                        回帖的得分率:0%                       
结贴的总数量:0                        结贴的总分数:0                        
无满意结贴数:0                        无满意结贴分:0                        
未结的帖子数:5                        未结的总分数:40                       
结贴的百分比:0.00  %               结分的百分比:0.00  %                  
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html

解决方案 »

  1.   

    要是执行完查询后就将所有的元组都存储到结果集中的话,ResultSet设计的是不是很傻呀
      

  2.   

    是以Object的形式存放在结果集中
    查询结束如果关闭结果集
    就啥都没有了
    所以一般都要存放到List中
      

  3.   

    查询出来的记录,当然是存在内存中,如果此时关闭ResultSet的话,这些记录就不存在了,所以,要先把这些记录通过循环,存在list里面,方才关闭ResultSet,然后再从list中读出来处理!
      

  4.   

    看看这个package com.shop.db;
    import java.sql.*;
    import java.io.*;/**************************************************
     * author:East(张栋芳)
     * date:2008-6-13
     * note:打开数据库的连接,和关闭连接
     **************************************************/public final class DataBaseOperator {

        public DataBaseOperator() {
        }
        
        /***
         *连接数据库用户指定driver,url,user,pwd
         */
        public static Connection createConnection(String driver,String url,String user,String pwd){
            Connection con = null;
            try{
                Class.forName(driver);
                con = DriverManager.getConnection(url,user,pwd);
            }catch(ClassNotFoundException ce){
                ce.printStackTrace();
            }catch(SQLException se){
                se.printStackTrace();
            }
            return con;
        }
        /***
         *连接数据库用户用默认的SQL server 2000的纯驱动
         */
        public static Connection createConnection(){
            String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
            String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=pubs";
            String user = "sa";
            String pwd = "";
            return createConnection(driver,url,user,pwd);
        }
        /***
         *创建一个连接通过配制文件
         */
        public static Connection createConnection(String fileName){
         String driver="";
         String url="";
         String user="";
         String pwd="";
         BufferedReader in = null;
         
         try{
          in =  new BufferedReader(new FileReader(fileName));
          driver = in.readLine();
          url = in.readLine();
          user = in.readLine();
          pwd = in.readLine();
          in.close(); 
         }catch(IOException ioe){
          ioe.printStackTrace();
          
         }
         return createConnection(driver,url,user,pwd);
        }
        /***
         *创建一个连接桥驱动
         */
        public static Connection createConnection(String driver,String url){
          driver = "sun.jdbc.odbc.JdbcOdbcDriver";
          url = "jdbc:odbc:myodbc";
         String user = "sa";
         String pwd = "";
         return createConnection(driver,url,user,pwd);
        }
        /***
         *关闭连接。con,pstmt,rs;
         */
        public static void closeAll(Connection con,PreparedStatement pstmt,ResultSet rs){
            try{
                    if(rs != null)rs.close();
                if(pstmt != null) pstmt.close();
                if(con != null) con.close();
            }catch(SQLException se){
                se.printStackTrace();
            }finally{
                rs = null;
                pstmt = null;
                con = null;        }
        }
        
        /***
         *关闭连接。con,pstmt;
         */ 
        public static void closeAll(Connection con,PreparedStatement pstmt){
            try{
                if(pstmt != null) pstmt.close();
                if(con != null) con.close();
            }catch(SQLException se){
                se.printStackTrace();
            }finally{
                pstmt = null;
                 con = null;
            }
        }
        /***
         *关闭连接。con
         */ 
        public static void closeAll(Connection con){
            try{
                if(con != null) con.close();
            }catch(SQLException se){
                se.printStackTrace();
            }finally{
                con = null;
            }
        }
        /**
         *关闭一个连接con,stmt,rs
         */
        public static void closeAll(Connection con,Statement stmt,ResultSet rs){
         try{
          if(con != null) con.close();
          if(stmt != null) stmt.close();
          if(rs != null) rs.close();
         }catch(SQLException se){
          se.printStackTrace();
         }
        }
        /**
         *关闭一个连接con,stmt
         */
        public static void closeAll(Connection con,Statement stmt){
         try{
          if(con != null) con.close();
          if(stmt != null) stmt.close();
         }catch(SQLException se){
          se.printStackTrace();
         }
        }}
      

  5.   

    ResultSet里面其实是一个集合,结果集里面的一条记录对应集合里面的一个对象,集合存放数据不限大小