Re: clarification needed in postgresql... + transactions...

From: Kris Jurka <books(at)ejurka(dot)com>
To: dinakar <din_akar(at)yahoo(dot)com>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: clarification needed in postgresql... + transactions...
Date: 2004-01-19 17:41:49
Message-ID: Pine.LNX.4.33.0401191236480.32357-100000@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Mon, 19 Jan 2004, dinakar wrote:

> hi all,
>
> i need a clarification in java + postgresql.
>
> currently iam using tomcat 4.0, jdk 1.4, postgresql
> 7.3.x.
>
> i using the below code to fetch data from database,
>
> con =
> DriverManager.getConnection("jdbc:postgresql://192.168.2.51:5432/wsas_test","wsas",
> "wsas");
>
> //con.setAutoCommit(false);
> System.out.println(con.getAutoCommit());
> preStmt = con.prepareStatement("BEGIN;SELECT
> fn_list_allpatients('cursor_name');");
> resultSet = preStmt.executeQuery();
> String strCn = "cursor_name";
> preStmt = con.prepareStatement("FETCH ALL IN \"" +
> strCn + "\";END;");
> resultSet = preStmt.executeQuery();
> //con.setAutoCommit(true);
> while (resultSet.next())
> {
> System.out.println(resultSet.getString(1) +
> resultSet.getString("patient_title"));
> }
>
> if i dont use the setautocommit to false and true
> respectively the above code is not working,

Writing BEGIN and END in your own code is frowned upon. Using
setAutoCommit and commit should be all you need.

> currently iam facing a problem that some transactions
> are ideal even after closing the connection to
> database...

You are probably not closing the connection. This could be the case of
just a missing close() or poor exception handling. If you post a self
contained test case someone will likely be able to identify your problem.

Kris Jurka

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jonathan Gold 2004-01-20 00:40:28 implementation of Statement.executeQuery()
Previous Message Kris Jurka 2004-01-19 17:35:59 Re: ResultSet.previous() - ArrayIndexOutOfBoundsException