Subject RE: [Firebird-Java] Execute Multiple Queries on a Single Connection
Author Hugh Purcell
Roman,

This reply you gave requires a response, because it reveals your true
spirit.

Time and again you teach with kind patience, you advise without arrogance,
your display generosity with your knowledge, you take those who are stuck
and give them the lines of code they need to put them back on track.

Though I haven't asked questions, I am reading and learning from you, and
everyone, as well.

Thank you.

Hugh Purcell

> -----Original Message-----
> From: Firebird-Java@yahoogroups.com [mailto:Firebird-Java@yahoogroups.com]
> On Behalf Of Roman Rokytskyy
> Sent: Friday, September 23, 2005 1:55 AM
> To: Firebird-Java@yahoogroups.com
> Subject: Re: [Firebird-Java] Execute Multiple Queries on a Single
> Connection
>
> > Is it possible Execute Multiple Queries on a Single Connection? I mean
> > use the two PrepareStatement at the same time within single
> > connection?
>
> Sure. But you have to set the auto-commit property to false. The JDBC
> specification requires explicitly to close the result set of one statement
> before the another is executed in auto-commit mode.
>
> > Here is my code:
> > =====================================
> > try {
> > Connection con = getConnection(); // Get the jayBird connection
>
> Add
>
> 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();
>
> And then here:
>
> con.commit();
>
> > }
>
> } catch(SQLException ex) {
>
> con.rollback();
>
> > } 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.
>
> Yes, that is correct - the JDBC specification requires this.
>
> Roman
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>