Subject Re: [Firebird-Java] Execute Multiple Queries on a Single Connection
Author Евгений Путилин
Hi, lintao
>
> 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?
Yes. If Connection is not autocommit mode.
If AutoCommit==true you can only one have open ResultSet at same time.
> Here is my code:
> =====================================
> try {
> Connection con = getConnection(); // Get the jayBird connection
con.setAutoCOmmit(false);
> 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();
>
> } con.commit();
> } finally {
> con.close();
> }
> } catch (SQLException exception) {
> System.err.print("Exception: ");
> System.err.println(exception.getMessage());
> }
>
> =====================================

WBR Eugeney Putilin.