Subject Execute Multiple Queries on a Single Connection
Author lintao_nz
Hi, all

I am quite new for Java. So here I have a simple JDBC question:

Is it possible Execute Multiple Queries on a Single Connection? I mean
use the two PrepareStatement at the same time within single

Here is my code:
try {
Connection con = getConnection(); // Get the jayBird connection
try {

String sqlModules = "Select * from modules";
String sqlStudentTest = "select * from join student_test"

ResultSet rModules, rStudentTest;

PreparedStatement pstmt;
pstmt = con.prepareStatement(sqlModules);
rModules = pstmt.executeQuery();

PreparedStatement pstmt2;
pstmt2 = con.prepareStatement(sqlStudentTest);

// Error: Exception: The result set is closed
while ( {
String title = rModules.getString("Title");

pstmt2.setString(1, rModules.getString("Module"));
rStudentTest = pstmt2.executeQuery();
while ( {

} finally {
} catch (SQLException exception) {
System.err.print("Exception: ");


Looks like once call 'pstmt2 = con.prepareStatement(sqlStudentTest);',
the rModules ResultSet has been closed.

How can I solve this problem? I don't think I need to use two
connection to do this.