This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes two ResultSet for one connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
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
 
 
subject: two ResultSet for one connection
 
Similar Threads
pulling the table names from a Database
Getting error while saving image as blob in oracle
Oracle Connection Pooling
Data Change Notification in Java
how to move data to other table