How to Create Data Source without Pooling in Tomcat

余生颓废 提交于 2019-12-07 07:26:26

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.

Does the JDBC driver you are using supply an implementation of javax.naming.spi.ObjectFactory or some other connection object that you could configure using org.apache.naming.factory.BeanFactory? Either of those solutions would not require you to write custom code or add any additional 3rd party libraries.

If you really want just one connection, try setting the intialSize to 1 and maxActive to 1 in your DBCP configuration.

In the long term, if you don't want to use connection pooling, then don't use JNDI to configure your datasource, just create it directly in the code of your web application.

Edit:

In your comment you say: "It only allows one connection and the server hangs right away because every request is waiting for the connection."

Yes, if you effectively turn off pooling by making the pool size 1, that is what will happen. But the title of your question is "How to Create DataSource without Pooling" so I'm confused about what exactly you are trying to accomplish.

My suggestion would be to not use JNDI to define your connections (the whole purpose of defining a JNDI datasource is for connection pooling across web applications). Instead, define your connection in your servlet code for your two cases, one case that continues to use DBCP, the other case that uses your other low-level connection pool.

I did it for an Oracle non-pooled connection like this:

<Resource
        name="jdbc/aqds"
        auth="Container"
        type="oracle.jdbc.pool.OracleDataSource"
        factory="oracle.jdbc.pool.OracleDataSourceFactory"
        url="jdbc:oracle:thin:@localhost:1521:XE"
        user="MYUSER"
        password="MYPASSWORD" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!