Cannot create JDBC driver of class '' for connect URL 'null' : Tomcat & SQL Server JDBC driver
Solution 1
The
context.xml
in your web application'sMETA-INF
folder will take precedence over the one in the /conf directory, which is really just a generic default.The open-source JTDS SQL Server driver is way better than Microsoft's. Unless there's an overriding reason, use it instead. The only reason to put it in your tomcat/lib folder is if you're declaring a GlobalNamingResource for the database in your server.xml, otherwise you can just put it in your application's /lib folder.
The JDBC URL for JTDS is:
jdbc:jtds:sqlserver://hostname/databasename
The connection driver class for JTDS is:
net.sourceforge.jtds.jdbc.Driver
Solution 2
In tomcat 6.0.36 it's exactly the opposite way:
CATALINA_HOME/conf/Catalina/your_host/context.xml
will take presedence over the one from
YourApplication/WebContent/META-INF/
After putting data following snippet inside the Context-Tag in Catalina/your_host
it worked in my case:
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/your_db" auth="Container" type="javax.sql.DataSource"
maxActive="50" maxIdle="30" maxWait="10000"
username="your_usr" password="your_pwd"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://your_host:3306/your_db"/>
See Tomcat Documentation on http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
aohm1989
Updated on July 09, 2022Comments
-
aohm1989 almost 2 years
I've tried just about everything I can find out there, if someone is able to help me out, I will be eternally grateful (and a lot more free in my time).
Basically, I have an error in Tomcat 7.0 (both when running within Eclipse and via startup.bat) that says this once data begins to be accessed by my dynamic web application:
Cannot create JDBC driver of class '' for connect URL 'null' java.lang.NullPointerException at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507) at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476) at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
I have the sqljdbc4.jar file in my tomcat\lib directory. I have also tried putting this in my WEB-INF/lib, and even my JDK lib directories. I don't think sqljdbc.jar will work, as it is intended for older JDK/JRE installs than mine.
I've heard the context.xml and web.xml files are crucial in getting this to work.
web.xml snippet:
<resource-ref> <description>LBI DB Connection</description> <res-ref-name>jdbc/LBIDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> <resource-ref> <description>OR DB Connection</description> <res-ref-name>jdbc/ORDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref>
context.xml
<Context> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <Resource name="jdbc/LBIDB" auth="Container" type="javax.sql.DataSource" username="***" password="***" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver:localhost;DatabaseName=YYBackOffice;SelectMethod=cursor;" maxActive="8" maxIdle="4"/> <Resource name="jdbc/ORDB" auth="Container" type="javax.sql.DataSource" username="***" password="***" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver:localhost;DatabaseName=XXBackOffice;SelectMethod=cursor;" maxActive="8" maxIdle="4"/>
The Context tab does have a closing tab, eventually.
Please help! If you need any more information, please let me know. Also, I'm not sure which context.xml ought to be modified, there are 2 in the Tomcat directories, one in the /conf folder, and one in the webapps/appname/META-INF folder. Sorry if it sounds like I'm a bit of a rookie, that's because I am!
Also, I've seen many different examples of the url="..." part of the context.xml, some including port numbers. I have tried several things out online, but nothing seems to work (doesn't help nothing online is my exact data environment, also I suppose it's challenging that this app queries two different DBs at given times).
Thoughts?
-
aohm1989 about 12 yearsThanks a lot for this clarification, I had heard so many things online with server.xml as well and using global resources, context.xml issues, etc. that it can be confusing for a newcomer. I bet this will help me in resolving my issue.
-
aohm1989 about 12 yearsFYI, changing to the JTDS SQL Server driver, and using the JDBC URL/driver class seemed to have worked. I can't tell for sure, but it does seem like the errors have went away! It turns out this web app has some other problems that weren't related to this I think, but this still helps a ton for my own purposes. Thanks a bunch.
-
clafonta about 8 yearsThis worked for me. My setup is Eclipse with a Tomcat-plugin, for debugging. For the initial setup, Eclipse places a basic 'context.xml' file in the
CATALINA_HOME/conf/Catalina/MY_MAGIC_APP/context.xml
. Maybe I did something wrong, but the Eclipse-Tomcat-plugin didn't pick-up or discover my projects realMETA-INF/context.xml
file, which contains the necessary configuration information. I replaced the basiccontext.xml
file with the realcontext.xml
file and all is good.