Subject | Re: [Firebird-Java] Execute Multiple Queries on a Single Connection |
---|---|
Author | Roman Rokytskyy |
Post date | 2005-09-23T05:54:32Z |
> Is it possible Execute Multiple Queries on a Single Connection? I meanSure. But you have to set the auto-commit property to false. The JDBC
> use the two PrepareStatement at the same time within single
> connection?
specification requires explicitly to close the result set of one statement
before the another is executed in auto-commit mode.
> Here is my code:Add
> =====================================
> try {
> Connection con = getConnection(); // Get the jayBird connection
con.setAutoCommit(false);
> try {And then here:
> 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();
con.commit();
> }} catch(SQLException ex) {
con.rollback();
> } finally {Yes, that is correct - the JDBC specification requires this.
> 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.
Roman