Java connection pool without JNDI?

I have a connection pool to access MySQL database from servlet I use JNDI to get the data source. JNDI is in my meta-inf / context XML file

Everything works normally, but I have to put the MySQL driver jar in Tomcat's / common / lib folder instead of webapp's WEB-INF / lib; Otherwise, JNDI will not work (classnotfoundexception: com. Mysql. JDBC. Driver)

Is there any other way to get the data source, which allows me to put jars in WEB-INF / lib? All the examples I found on the Internet are using JNDI

(this is a very simple application. I really don't want to import 53 jars of some frameworks to solve my problem:)

thank you!

Solution

Although most of these replies are about the swimming pool, I don't think it's your problem?

I think the most direct answer to your question is simply to import and use the datasource implementation provided by your driver Are you using MySQL connector / J? Then it is mysqldatasource

There are ways to set user name, password, etc

If you don't need it in JNDI, you don't have to configure it in JNDI through Tomcat You can keep the driver jar in Web - inf / lib If you want to gather around this datasource, in fact, you only need to use common DBCP and pool

This is to make your own pooling datasource out of a given datasource An example of

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>