From: dmp <danap@ttc-cmc.net>
To: Joseph Pravato <joseph.pravato@nomagic.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Automatic transactions in SELECT
Date: Thu, 28 Feb 2013 18:21:40 -0700
Message-ID: <513002A4.7070105@ttc-cmc.net> (raw)
In-Reply-To: <512FC16E.50109@nomagic.com>
References: <512F84ED.3050002@nomagic.com>
<512F92A0.5060200@ttc-cmc.net>
<512FC16E.50109@nomagic.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
After review I do not see a problem with the way pgJDBC handles transactions
appropriately during the failure in your test case. As indicated by others
replies this is an architicture decision to properly handle failure.
Basically as indicated you can continue to use SquirrelSQL and modify the
code to handle the behavior or convice the project to do so. Or move on
to another application or your own to handle the behavior you desire.
Your code to properly handle the exception and continue processing. I'm
sure this is not what may be pertinent to your situation but demostrates
how an application could possibly handle the situation.
danap.
try
{
conn.setAutoCommit(false);
Statement st1 = conn.createStatement();
String sqlStatementString = "create table example ( " +
" name varchar(255), " +
" primary key(name) " +
")";
System.out.println(sqlStatementString);
st1.execute(sqlStatementString);
st1.close();
conn.commit();
try
{
Statement query = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
sqlStatementString = "select nam from example";
System.out.println(sqlStatementString);
query.executeQuery(sqlStatementString);
query.close();
}
catch(Exception e)
{
System.out.println("Exception Inner Try");
conn.rollback(); // Added
e.printStackTrace();
}
Statement query2 = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
sqlStatementString = "select name from example";
System.out.println(sqlStatementString);
query2.executeQuery(sqlStatementString);
query2.close();
conn.commit();
//conn.rollback(); << Change
Statement st3 = conn.createStatement();
sqlStatementString = "drop table example";
System.out.println(sqlStatementString);
st3.execute(sqlStatementString);
st3.close();
conn.commit();
System.out.println("Finished.");
conn.setAutoCommit(true); // Return autocommit
}
catch (Exception sqle)
{
System.out.println("Exception Outer Try");
System.out.println("Exeception" + sqle);
// Roll back.
try
{
conn.rollback();
}
catch (Exception ee)
{
System.out.println("Failed to Rollback");
}
}
Joseph Pravato wrote:
>
>> Hello Joseph,
>>
>> If you can provide some kind of test case to duplicate the problem I
>> would happy to take a look to see if there is an issue with the pgJDBC.
> Thank you for the response, we have gone ahead and provided a Java test case for you.
>
> Basically we have run the queries outside of SquirrelSQL and we still happen to get the same error when we directly access the database
> through the JDBC driver. At this time we do not believe that this is a SquirrelSQL problem since we get this transaction error directly through
> java.
>
> http://pastebin.com/vg8J0kZi
>
> Your input would be appreciated.
>
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: danap@ttc-cmc.net, joseph.pravato@nomagic.com
Subject: Re: Automatic transactions in SELECT
In-Reply-To: <513002A4.7070105@ttc-cmc.net>
References: <512F84ED.3050002@nomagic.com> <512F92A0.5060200@ttc-cmc.net> <512FC16E.50109@nomagic.com> <513002A4.7070105@ttc-cmc.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox