Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Multiple Queries with JDBC

807607Sep 26 2006 — edited Oct 11 2006
Hello. I'm somewhat new to all of this, so forgive me if this is something really basic.

I'm developing an application which must interact with my MySQL database pretty frequently, however it seems to me that I am unable to, essentially, have multiple ResultSets open at a given time, which as a result prevents me from making multiple queries simultaneously. The essential problem is...
ResultSet rs = statement.execute( "SELECT * FROM table");
if (rs.next())
{   
    ResultSet srs = statement.execute( "SELECT * FROM table2");
    rs.getInt("id");
}
...Yields a NullPointerException on line 5. If I am correct in my understanding, this is due to a ResultSet closing when it's statement is used a second time.

My best guess to solving this problem is to create a pool of statement objects (which would essentially be a number of connections to the DB), and then use the first open statement object (or a newly created one) to run a particular query... however this seems rather sloppy. Not to mention that, offhand, I'm not even sure if I can have multiple connections open to the DB at the same time. Is there any better way to run multiple queries at the same time with JDBC?

Thanks in advance for any help.
-Jess

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 8 2006
Added on Sep 26 2006
81 comments
6,234 views