Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-jdbc by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group