把ResultSet中的数据取出来,放到别的对象中去
因为当连接关闭的时候ResultSet会失效

解决方案 »

  1.   

    绝对没有
    所有偶用ejb的时候,经常要自己把数据全放到一个集合里面去
    是在不爽阿
      

  2.   

    sun.jdbc.rowset.CachedRowset
    实现了rowset的所有方法,但是有可以脱离连接存在
    例子:
      //输入:sql语句
      //输出:查询的结果集
      public CachedRowSet executeQuery(String sql) throws java.sql.SQLException {
        CachedRowSet cst = new CachedRowSet();
        try {
          conn = db.getConnection();
          ps = conn.createStatement();
          rs = ps.executeQuery(sql);
          cst.populate(rs);
          rs.close();
        }
        catch (SQLException e) {
          System.out.println(e.getMessage());
        }
        finally {
          db.CleanConnection(conn, ps, rs);
        }
        return cst;
      }
    取出来了就可以直接用了
      

  3.   

    放到Vector中或数组中都是现有的解决办法。
    推荐放到Vector中。
      

  4.   

    sun.jdbc.rowset.CachedRowset
    如果需要可以找我要。
    提供了所有rowset所有方法,但是又是断开了数据库连接的。
    那种好,我就不说了。
      

  5.   

    不好意思,贴子发了两遍,大家到http://expert.csdn.net/Expert/topic/1897/1897580.xml?temp=.3481867
    去回答吧,谢谢。
    有认够狠,两边都回答了,呵呵。sun.jdbc.rowset.CachedRowset
    这个包哪里找?什么文件名?
      

  6.   

    java.lang.Object
      |
      +--sun.jdbc.rowset.BaseRowSet
            |
            +--sun.jdbc.rowset.CachedRowSet
                  |
                  +--org.arch4j.dataaccess.visitors.ResultSetCacheAll Implemented Interfaces: 
    Cloneable, ResultSet, ResultSetVisitor, javax.sql.RowSet, javax.sql.RowSetInternal, Serializable --------------------------------------------------------------------------------
      

  7.   

    :      清单1:简单明了的CachedRowSet初始化方法 <jsp:useBean id="Contacts" 
                 class="sun.jdbc.rowset.CachedRowSet" 
                 scope="session"> 
    <% 
      // load database driver 
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
      // initialize our CachedRowSet bean 
      Contacts.setUsername("dbuser"); // example userid 
      Contacts.setPassword("dbpassword"); // example password 
      Contacts.setUrl("jdbc:odbc:ContactDB"); // example DSN 
      Contacts.setCommand("SELECT name, telephone from Contacts"); 
      Contacts.execute(); 
    %> 
    </jsp:useBean>
      

  8.   

    http://oldsite.linuxaid.com.cn/developer/showdev.jsp?i=315
      

  9.   

    说实话,不回答你的问题,我还不知道,cachedrowset功能这么强大。连数据库的连接都可以一个人搞定
    <%@ page import="sun.jdbc.rowset.CachedRowSet" %> 
    <HTML> 
    <HEAD> 
    <jsp:useBean id="Contacts" class="sun.jdbc.rowset.CachedRowSet" scope="session"> 
    <% 
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
      // initialize our CachedRowSet bean 
      Contacts.setUsername("user"); 
      Contacts.setPassword("password"); 
      Contacts.setUrl("jdbc:odbc:mydsn"); 
      // some drivers require this 
      Contacts.setTableName("Contacts"); 
      Contacts.setCommand("SELECT name, telephone from Contacts"); 
      Contacts.execute(); 
      Contacts.first(); 
    %> 
    </jsp:useBean> <% 
      // get the servlet request object 
      javax.servlet.ServletRequest req = pageContext.getRequest();   // process updates 
      boolean updateRow = false; 
      String contactName = Contacts.getString(1); 
      String newValue = req.getParameter("ContactName"); 
      if (( newValue != null) && (!newValue.equals( contactName ))) { 
        Contacts.updateString( 1,req.getParameter("ContactName")); 
        updateRow = true; 
      } 
      String contactPhone = Contacts.getString(2); 
      newValue = req.getParameter("ContactPhone"); 
      if (( newValue != null) && (!newValue.equals(contactPhone))) { 
        Contacts.updateString( 2,req.getParameter("ContactPhone")); 
        updateRow = true; 
      } 
      if (updateRow) Contacts.updateRow();   // process navigation commands 
      if ( req.getParameter("next") != null ) { 
        if (! Contacts.next() ) Contacts.last(); 
      } else if ( req.getParameter("prev") != null) { 
        if (! Contacts.previous()) Contacts.first(); 
      } else if ( req.getParameter("save") != null) { 
        Contacts.acceptChanges(); 
      } else if ( req.getParameter("insert") != null) { 
        Contacts.moveToInsertRow(); 
        Contacts.updateString(1, ""); 
        Contacts.updateString(2, ""); 
        Contacts.insertRow(); 
        Contacts.moveToCurrentRow(); 
        Contacts.next(); 
      } else if ( req.getParameter("delete") != null) { 
        Contacts.deleteRow(); 
        if (!Contacts.next()) Contacts.last(); 
      } 
    %> 
    <STYLE> 
      BODY { font-style: verdana } 
    </STYLE> 
    <TITLE> 
    CachedRowSetExample 
    </TITLE> 
    </HEAD> 
    <BODY BGCOLOR='lightgrey'> 
    <H2>Contacts</H2> 
    <FORM> 
    <TABLE BORDER='0'> 
    <TR><TD>Name:</TD><TD>Telephone number:</TD></TR> 
    <TR> 
    <TD><INPUT TYPE='text' 
               NAME="ContactName" 
               VALUE='<%=Contacts.getString(1)%>' /></TD> 
    <TD><INPUT TYPE="text" 
               NAME="ContactPhone" 
               VALUE='<%=Contacts.getString(2)%>' /></TD> 
    </TABLE> 
    <INPUT TYPE="submit" NAME="prev" VALUE=" < "/> 
    <INPUT TYPE="submit" NAME="next" VALUE=" > "/> 
    <INPUT TYPE="submit" NAME="insert" VALUE="Insert"/> 
    <INPUT TYPE="submit" NAME="delete" VALUE="Delete"/> 
    <INPUT TYPE="submit" NAME="save" VALUE="Save"/> 
    Record <%=Contacts.getRow()%> of <%=Contacts.size()%> 
    </FORM> 
    </BODY> 
    </HTML> 
      

  10.   

    gks_cn(981530) 谢谢,我在那边给你多些,这边少些,反正满100就是。另:Java为何这么乱啊?Delphi就一家厂商控制,所以比较纯,第三方控件也很多,不多说了。.Net好像发展势头很猛,大家有何看法?
      

  11.   

    就在这边回答吧。http://expert.csdn.net/Expert/topic/1897/1897580.xml?temp=.3481867
    那边被我咔嚓了。有无别的办法呢?
    幸亏,昨天我差点想自己写一个类。不然又是一堆垃圾。