Re: how do i start and end a transaction with hsqlb?
Jorge Garcia de Alba <[email protected]> Sun, 5 May 2019 08:02:38 -0500
| Newsgroups | gmane.comp.java.hsqldb.user |
|---|---|
| Message-ID | <CAEVgvV_WW7fhsk23O--jDBci2ykH6vOWqZb+Qn+RhVegmnS3OA@mail.gmail.com> |
Procedures are sql-invoked routines and I use callablestatement to call them. When I cause an exception as a debugging measure I expect for database changes to rollback but it is not happening even if connection.setAutoCommit(false). On 5/5/19, Fred Toussi via Hsqldb-user <[email protected]> wrote: > It is not clear what you mean by procedures. How do you call the > procedures? > > All procedures have BEGIN ATOMIC in their declaration. If there is an > exception inside the procedure, for example by a constraint violation, the > work of the procedure is rolled back. The exception is then thrown as an > SQLException by the JDBC CallableStatement method that was called. > > If you want to throw an exception in the procedure, use the SIGNAL > statement: > SIGNAL SQLSTATE <state value> > > > On Sun, May 5, 2019, at 11:31, Jorge Garcia de Alba wrote: >> When I use connection.setAutoCommit(false), run my procedures and >> cause an exception it is not rolling back so I was wondering if I >> missed a configuration setting or something. >> >> On 5/5/19, Fred Toussi via Hsqldb-user >> <[email protected]> wrote: >> > A transaction is started when you execute the first insert, update or >> > delete >> > statement or procedure. The connection.commit() call commits the >> > transaction. A connection.rollback() rolls it back to the start of the >> > transaction. >> > >> > You just connect to your HSQLDB database to obtain your >> > java.sql.Connection >> > object and run your code. HSQLDB is always transaction but you can >> > change >> > the details if you want to. See the Guide, Sessions and Transactions >> > chapter. >> > >> > Fred Toussi >> > >> > On Sun, May 5, 2019, at 03:41, Jorge Garcia de Alba wrote: >> >> Hello, >> >> >> >> I would like to run a batch of statements and/or procedures and if >> >> there is an exception rollback. >> >> >> >> Something like: >> >> >> >> try >> >> { >> >> connection.setAutoCommit(false); >> >> //insert, update, delete statements and/or procedures >> >> connection.commit(); >> >> } >> >> catch (Exception e) >> >> { >> >> connection.rollback(); >> >> } >> >> >> >> How do I setup hsqldb to do this? >> >> >> >> jr >> >> >> >> >> >> _______________________________________________ >> >> Hsqldb-user mailing list >> >> [email protected] >> >> https://lists.sourceforge.net/lists/listinfo/hsqldb-user >> >> >> > >> > >> > _______________________________________________ >> > Hsqldb-user mailing list >> > [email protected] >> > https://lists.sourceforge.net/lists/listinfo/hsqldb-user >> > >> >> >> _______________________________________________ >> Hsqldb-user mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/hsqldb-user >> > > > _______________________________________________ > Hsqldb-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/hsqldb-user >