I\'m trying to set up a JDBC DataSource in Tomcat 7 under Ubuntu 12.X, so I added the following to the context.xml file:
The cause is a issue in the Ubuntu build/package process for Tomcat7. If I understand the issue correctly, Apache builds tomcat-dbcp.jar from binary files, while Ubuntu builds packages only from source. The Ubuntu project ends up needing to change the Java package name, which tends to break things for us poor users. The gory details may be found at the Ubuntu issues list.
The solution I found is to name the data source factory when I define the resource. In one case, I have a META-INF/context.xml file that contains:
<Resource name="jdbc/myDataSource"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/myDatabase"
username="username" password="password"
validationQuery="SELECT COUNT(*) FROM MY_TABLE"
factory="org.apache.commons.dbcp.BasicDataSourceFactory" />
The critical element is the "factory" declaration, which overrides the built-in default.
On our production machines, the resource is defined in the GlobalNamingResources element of the server.xml file. Specifying the factory is only needed on the Ubuntu systems.
i had the same problem on CentOS. I got arounbd this by downloading a fresh copy of tomcat from site and uploaded tomcat-dbcp.jar to my online server lib, restart server :)
The library tomcat-dbcp-7.0.30.jar
from repositories is corrupted.
Replace it with:
sudo wget -O /usr/share/java/tomcat-dbcp-7.0.30.jar http://search.maven.org/remotecontent?filepath=org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
I had the same problem on Fedora 20 with Tomcat 7.0.55. I replaced the 7.0.30 with 7.0.55 in the file path and file name and this worked for me. Not sure why but this file was completely missing from the YUM install for tomcat 7. Cant use a database without it.
That did it.
Make sure if the tomcat-dbcp-7.0.30.jar file does not have the below size, then it may be corrupt and you may need to replace it by the sudo wget command above.
-rw-r--r-- 1 root root 235411 May 1 2013 tomcat-dbcp-7.0.30.jar
lrwxrwxrwx 1 root root 22 Jan 10 2013 tomcat-dbcp.jar -> tomcat-dbcp-7.0.30.jar
If you don't feel like patching tomcat you can (on CentOS) also add the following to the JAVA_OPTS (e.g. by adding it in /usr/share/tomcat/conf/context.xml
JAVA_OPTS="-Djavax.sql.DataSource.Factory=org.apache.commons.dbcp.BasicDataSourceFactory"