Subject | Re: [Firebird-Java] Execute Multiple Queries on a Single Connection |
---|---|
Author | Евгений Путилин |
Post date | 2005-09-23T06:20:20Z |
Hi, lintao
If AutoCommit==true you can only one have open ResultSet at same time.
>Yes. If Connection is not autocommit mode.
> 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?
If AutoCommit==true you can only one have open ResultSet at same time.
> Here is my code:con.setAutoCOmmit(false);
> =====================================
> try {
> Connection con = getConnection(); // Get the jayBird connection
> try {WBR Eugeney Putilin.
>
> 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());
> }
>
> =====================================