Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dirty reads within a transaction

843854Dec 26 2002 — edited Dec 27 2002
Hello,

I have a method which inserts a record into a table and returns the primary key of the record which is generated via a trigger on insert.The problem is that I cannot read the row within the same transaction.Unless I do a explicit commit the select query keeps on returning 0 records.

I am using the same Statment object to execute both insert and select queries. How can I read uncommitted data within the same transaction. I thought using the same statement object would allow me to do that.
I tried to set the transaction isolation level to read uncommitted before the insert statement but oracle 9i drivers allow only read committed and serializable transaction levels.

Any help is appreciated.

Here is the code.

//insert.
connection.setAutoCommit(false);
String insert_query = " insert into employee " .....
stmt = connection.createStatement();
stmt.executeUpdate(insert_query);

//select
select_query = "select employee_id from employee where ... ";
stmt.executeQuery(select_query);
if (rs.next())
{
int primary_key = rs.getInt(1);
}

stmt.close();
connection.commit();
connection.setAutoCommit(true);
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 24 2003
Added on Dec 26 2002
2 comments
449 views