Java – How to Create Data Source without Pooling in Tomcat

apache-commons-dbcpjavajdbcjnditomcat

I use JNDI context to create datasource for JDBC drivers in Tomcat's context.xml file like this,

<Resource name="db/test" 
          type="javax.sql.DataSource" 
          driverClassName="com.test.jdbc.Driver"
          url="jdbc:fastdb://localhost:3306/session_db?autoReconnect=true&amp;connectTimeout=5000&amp;socketTimeout=5000"
          zeroDateTimeBehavior="convertToNull"
          username="dbuser"
          password="password"
          maxActive="100"
          maxWait="2"
          removeAbandoned="true"
          removeAbandonedTimeout="60"
          logAbandoned="true" />

By default, Tomcat will use DBCP data source factory and created pooling data sources. The specific database and driver we use already supports pooling in lower level and the extra pooling actually hurts performance. Is there anyway to create basic datasource (without pooling) using JNDI resource like this so I can switch between different databases with minimum configuration changes?

I know I can write my own datasource factory or use the ones from other drivers to achieve this but I am looking for an easier solution.

Best Answer

Not quite sure, if this is something that would satisfy you, but you can always use Spring JDBC support without using datasources managed by Tomcat.

Related Topic