Db2 – Set uncommitted read as default in Oracle SQL Developer with DB2 database

db2oracle-sql-developer

I am using SQL Developer with a IBM DB2 database. I am only querying the data for analytical purposes – never making any updates, additions or deletions. I was wondering if there is a way to ensure that every query is an uncommitted read by default so that I never lock the tables. Is there a way that I can do this without typing FOR FETCH ONLY WITH UR at the end of every query? Would enabling the settings for Autocommit in Preferences -> Database -> Advanced achieve the same goal (not lock tables)?

Best Answer

There are a couple of ways to achieve this. Firstly, you can simply run the statement

SET CURRENT ISOLATION UR

in your session before executing other statements.

Alternatively, you can set a property in the JDBC URL you use to connect to the database, like so:

jdbc:db2://host:port/database:defaultIsolationLevel=1;

The value 1 corresponds to the constant java.sql.Connection.TRANSACTION_READ_UNCOMMITTED (note that it is implementation-dependent and may break).