I am running Tomcat 5.5 and Java JDK 1.6. I am facing a jdbc connectivity issue while trying to connect to a local Oracle database (version 11.1.0) installed on my laptop. The required changes-I trust-have been made in the files context.xml and web.xml. The relevant listings from both files are as follows:
<!-- The contents of this file will be loaded for each web application -->
<!-- Default set of monitored resources -->
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<Manager pathname="" />
<!-- Oracle DB Connection Pool -->
<Resource name="jdbc/myOracle" auth="Container"
username="hr" password="hr" maxActive="20" maxIdle="10"
I have placed the relevant jar file ojdbc6.jar in the directories CATALINA_HOME/common/lib as well as [web app name]/WEB-INF/lib. In spite of all this, the error message received is as follows (partial listing):
org.apache.jasper.JasperException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/myOracle"
javax.servlet.ServletException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/myOracle"
Remove the Oracle jar from your WAR. There's rarely a good reason to put a database driver in the app instead of the server, and when you have them in both places, you risk having classpath problems.
Verify that the driver classname is, in fact represented in your JDBC JAR (use "jar -tvf ojdbc6.jar") and that you've spelled it right.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Sep 21, 2005
I have removed the ojdbc6.jar file from the WEB-INF/lib directory and still the same results. I have verified that the jar file has the file OracleDriver.class. Here is the code I am using to test the database connectivity issue.
I don't see anything wrong with your spec files, but I'm not sure about putting the jar in TOMCAT_HOME/common/lib. I think there's a server/lib directory in Tomcat 5.5. They simplified it in Tomcat6 so I don't remember. But regardless of its exact name, the server-only lib directory is where you want the jar, since the server owns the connection pool, not the app.
Joined: Sep 21, 2005
Placed the jar file under server/lib instead of common/lib and also added the entry of the jar file in PATH variable-still no luck. The database indeed works with tools like Oracle SQL*Plus and JDeveloper.
Also, I am wondering about the significance of the string value in the entry driverClassName="oracle.jdbc.OracleDriver" in the file context.xml. Shouldn't the driverClassName should be just 'OracleDriver'? Does the path to the class file be identical to the one in the definition above? Please advise.
No, you do need to specify the fully-qualified class name in your configuration. And what you specify does have to be the fully-qualified name of a class which is actually in that jar file which -- hopefully -- is now in the right place. And did you restart the server?
PATH has no meaning for Java, only CLASSPATH. However, Tomcat maintains its classpaths by internal configuration, not by by the external environment, so even modifying CLASSPATH would not help.
Your driverClassName does have to be the fully-qualified classname, so "OracleDriver" wouldn't work. But the message you're getting is consistent with the driver not being found in the classpath, which is why I asked you to scan the ojdbc6.jar file to make sure it was in there.
I'm not working with Oracle just now, so I don't have any reference projects I can check, but I did use Oracle for years and what you're doing is close enough that my memory (what's left of it) doesn't detect anything obviously wrong. Most likely it's something like a mis-capitalized bit of text or a ":" out of place. See if you can't find some example Oracle JDBC connection URLs for the version of Oracle you're running and verify you have it letter-for-letter perfect. It's not going to offer any hints, alas.
I got it to work finally. As per the Tomcat documentation, the jar file-ojdbc6.jar-needs to be present only in $CATALINA_HOME/common/lib directory. I had the jar file in this directory earlier also, but don't know why it threw up errors. The only concrete thing which comes to my mind is that while trying different options, I had changed the value for the type attribute from "javax.sql.DataSource" to ""javax.jsp.jstl.sql.DataSource" in the context.xml file. Think I didn't change it back after copying the jar file. Anyways, it works now.
I was almost giving up. Thank you all for the tips and help.
Actually, it's possible that you had junk classes in your Tomcat work directory, which is something I forgot about. Two things that are always good to do when redeploying are to delete the exploded WAR (if there is one) from your webapps directory (otherwise, Tomcat will use IT instead of the newer .war file!) and to delete the workfiles from TOMCAT_HOME/work/Catalina/localhost.