Обсуждение: JDBC: "transaction aborted"

Поиск
Список
Период
Сортировка

JDBC: "transaction aborted"

От
Pif
Дата:
Hello,

I use a connection pool (autocommit disabled). In some action servlet
of my website, I have "begin" and commit/rollback commands.
All work well.

But in my JSP page, when a select fail with JDBC exception, then I
cannot retry because of this exception :
"ERROR: current transaction is aborted, commands ignored until end of
transaction block"

So, since I only do select and I do not declare a begin statement, why
is there a transaction !? how can I choose that I don't want
transactions out of a begin/commit/roolback context !?

Thanks a lot.


PG 8.4

Re: JDBC: "transaction aborted"

От
Fabien JALABERT
Дата:
Hello, if I turn on autocommit, will I be able to process transactions
with begin/commit/rollback as before ?

Thanks.

Craig Ringer wrote:
>
> Turn autocommit on.
>
> --
> Craig Ringer
>
>


Re: JDBC: "transaction aborted"

От
Oliver Jowett
Дата:
Fabien JALABERT wrote:
> Hello, if I turn on autocommit, will I be able to process transactions
> with begin/commit/rollback as before ?

"Maybe" - but you shouldn't be doing that anyway. The JDBC model expects
that to do explicit transaction demarcation, you turn off autocommit and
use methods on Connection to do commit/rollback. You shouldn't be
issuing queries with explicit BEGIN/COMMIT/ROLLBACK.

see e.g.
http://download.oracle.com/javase/1.3/docs/guide/jdbc/getstart/connection.html#1004665

-O

Re: JDBC: "transaction aborted"

От
Craig Ringer
Дата:
On 01/09/10 15:40, Fabien JALABERT wrote:
> Hello, if I turn on autocommit, will I be able to process transactions
> with begin/commit/rollback as before ?

If you mean issuing explicit "BEGIN", "COMMIT" and "ROLLBACK" statements
as SQL text through the JDBC driver ... honestly, I'm not sure. It's not
really how the JDBC interface is intended to work.

Typically when using JDBC you would let the driver take care of this.
You call

  conn.setAutoCommit(false);

... to open a transaction. Any work between then and a subsequent:

  conn.commit()

or

  conn.rollback()

is done in the transaction.



--
Craig Ringer

Tech-related writing: http://soapyfrogs.blogspot.com/