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
connection?

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 (rModules.next()) {
String title = rModules.getString("Title");

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

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

=====================================

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.

Cheers,

Tao