Two Laptop Bag
The moose likes JDBC and the fly likes two ResultSet for one connection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "two ResultSet for one connection" Watch "two ResultSet for one connection" New topic
Author

two ResultSet for one connection

ZhiningZhang
Greenhorn

Joined: Jun 13, 2001
Posts: 18
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

Joined: Jun 13, 2001
Posts: 18

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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: two ResultSet for one connection
 
Similar Threads
Data Change Notification in Java
Getting error while saving image as blob in oracle
Oracle Connection Pooling
how to move data to other table
pulling the table names from a Database