I have a web application running in Tomcat 6, and I've managed to configure it to use the built-in DBCP connection pooling, and all is working very well, however I suspect it is running in the wrong isolation level on the database. I'd like it to run in read uncommitted, but I think it's running in read committed and don't know how to set it.
Here is my context's XML file:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true">
<Resource
name="jdbc/Connection"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://...etc..."
/>
</Context>
And this is the Java method used to get a database connection.
public Connection getDatabaseConnection() throws ServletException {
try {
InitialContext cxt = new InitialContext();
if ( cxt == null ) {
throw new ServletException( "ServletContext unavailable." );
}
DataSource ds = (DataSource)cxt.lookup( "java:/comp/env/jdbc/Connection" );
if ( ds == null ) {
throw new ServletException( "Data source not found!" );
}
Connection conn = ds.getConnection();
return conn;
} etc...
Having obtained the connection in getDatabaseConnection()
I realise I could manually set the isolation level with conn.setIsolationLevel( Connection.TRANSACTION_READ_UNCOMMITTED )
but that feels wrong as it either involves hard-coding the isolation level into the Java, or performing a look-up to the servlet context every time a new connection is required.
Can I define this in the context XML somehow, or is there a better approach I'm not aware of?