Subject Re: Transaction question
Author Roman Rokytskyy
Hi,

> I'm trying to create a transaction with this code:
>
> try
> {
> conex.getConnection().setAutoCommit(false);
> conex.getConnection().createStatement().execute("set transaction
> name tr1 read committed");
> ...
> Can anybody guide me on how to begin-commit a transaction.

Try to read JDBC tutorial. Transactions in JDBC are started
automatically before the first statement is executed. Transaction do
not have names and there can be only one transaction per connection.
Transaction isolation level is set using
Connection.setTransactionIsolation(int) method.

You code should look like this:

Connection con = connex.getConnection();

try {
con.setAutoCommit(false);
con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);

Statement stmt = con.createStatement();
try {
ResultSet rs = stmt.executeQuery("select * from my_table");
...
} finally {
stmt.close();
}
} finally {
con.close();
}

con.commit();