Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

two ResultSet for one connection

 
ZhiningZhang
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all,
My code is like
==============================
Connection conn = ...
Statement stmt = conn.createState();
Statement stmt2 = conn.creatState();
ResultSet rs = stmt.executeQuery("select * from mytable");
while( rs.next() )
{
ResultSet rs2 = stmt2.executeQuery("select * from mytable222"); // error here !!!
}
}
======================
I got Exception
======================
ava.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:2494)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:314)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:229)
==================================
But if I change my code to
========================
Connection conn = ...
Connection conn2 = ... // new connection
Statement stmt = conn.createState();
Statement stmt2 = conn2.creatState(); // using conn2
========================
it works. My question is that "do I really need another Connectin?" Thanks! -Zhining
 
ZhiningZhang
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi, i solved my problem.
Connection conn = ...
Statement stmt = conn.createState(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
Statement stmt2 = conn.creatState(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
=======
it works by using only one connection.
Thanks anyway!
-Zhining
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!