Statement stm = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rstb1 = stm.execute("Select * from table1");
ResultSet rstb2 = stm.execute("Select * from table2");stm执行了第二个查询以后 rstb1还在缓存中么?还有一个疑问 如果不是使用同一个stm对象 但是查询同一张表,第二次查询出来后缓存中会有2个ResultSet 还是同一张表只会有一个ResultSet缓存查了下文档说Statement对象销毁和重新执行时ResultSet会自动关闭
这里的重新执行是指重新执行同一张表 才会关闭ResultSet
还是只要执行了SQL语句就会关闭ResultSet

解决方案 »

  1.   

    By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. stm执行了第二个查询以后 rstb1 当然不在了。TYPE_SCROLL_INSENSITIVE indicating the type for a ResultSet object that is scrollable but generally not sensitive to changes made by others. 第二次查询出来后当然会有不同的内容。All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists. 只要执行了SQL语句就会关闭已经打开的ResultSet 。
      

  2.   

    你可以这样理解。
    ResultSet 只不过是一个记录集。
    读数据的时候。ResultSet - Statment -- Connection -- DB中间就像一个管道。通向数据库。
    而Statement 就是这个管道口。接着ResultSet;
      

  3.   

    谢谢 zhigangxie 
    现在了解一个Statement 只会保持一个结果集
    TYPE_SCROLL_INSENSITIVE 文档上大体意思是 缓存的结果集对数据源的变更不敏感 (大概是这个概念吧)
    不过还是没明白 
    2个Statement 执行了同一条查询以后 
    缓存的结果集会有几个?
    会缓存2个结果集在内存中吧?
      

  4.   

    stm执行了第二个查询以后 rstb1还在缓存中么? 当然。同一个Statement如果执行两次查询,那么第一次的结果就被丢弃,你可以看做被第二次覆盖。
      

  5.   

    2个。
    ResultSet1 - Statment1 -- Connection -- DB 
    ResultSet2 - Statment2 -- Connection -- DB