无法为连接URL'null'创建类''的JDBC驱动程序:Tomcat& SQL Server JDBC驱动程序 [英] Cannot create JDBC driver of class '' for connect URL 'null' : Tomcat & SQL Server JDBC driver

查看:904
本文介绍了无法为连接URL'null'创建类''的JDBC驱动程序:Tomcat& SQL Server JDBC驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经试过了一切我可以找到的,如果有人能够帮助我,我会永远感激(和更多的自由在我的时间)。



基本上,我有一个错误在Tomcat 7.0(当运行在Eclipse和通过startup.bat),这说明,一旦数据开始被我的动态Web应用程序访问:



无法为连接URL创建类''的JDBC驱动程序'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)



我在tomcat \lib目录中有sqljdbc4.jar文件。我也试过把它放在我的WEB-INF / lib,甚至我的JDK lib目录。我不认为sqljdbc.jar将工作,因为它是为我的老JDK / JRE安装。



我听说过context.xml和web。



web.xml片段:

 < resource-ref> 
< description> LBI DB连接< / description>
< res-ref-name> jdbc / LBIDB< / res-ref-name>
< res-type> javax.sql.DataSource< / res-type>
< res-auth>容器< / res-auth>
< res-sharing-scope>可共享< / res-sharing-scope>
< / resource-ref>
< resource-ref>
< description>或数据库连接< / description>
< res-ref-name> jdbc / ORDB< / res-ref-name>
< res-type> javax.sql.DataSource< / res-type>
< res-auth>容器< / res-auth>
< res-sharing-scope>可共享< / res-sharing-scope>
< / resource-ref>



context.xml

 < Context> 
<! - 默认的受监视资源集 - >
< WatchedResource> WEB-INF / web.xml< / WatchedResource>
< Resource name =jdbc / LBIDBauth =Container
type =javax.sql.DataSourceusername =***password =***driverClassName =com .microsoft.sqlserver.jdbc.SQLServerDriver
url =jdbc:sqlserver:localhost; DatabaseName = YYBackOffice; SelectMethod = cursor;
maxActive =8maxIdle =4/>

< Resource name =jdbc / ORDBauth =Container
type =javax.sql.DataSourceusername =***password =*** driverClassName =com.microsoft.sqlserver.jdbc.SQLServerDriver
url =jdbc:sqlserver:localhost; DatabaseName = XXBackOffice; SelectMethod = cursor;
maxActive =8maxIdle =4/>

上下文选项卡最终有一个关闭选项卡。



请帮忙!如果您需要任何更多的信息,请让我知道。此外,我不知道应该修改哪个context.xml,Tomcat目录中有2个,/ conf文件夹中有一个,webapps / appname / META-INF文件夹中有一个。对不起,如果它听起来像我有点新手,这是因为我是!



此外,我看到了许多不同的例子的url =.. 。是context.xml的一部分,一些包括端口号。我已经尝试了几个在线,但没有什么似乎工作(不帮助没有在线是我的确切的数据环境,我想这是有挑战性的,这个应用程序查询两个不同的DB在给定的时间)。



想法?

解决方案


  1. <$ c $您的web应用程序的 META-INF 文件夹中的c> context.xml 将优先于/ conf目录中的,通用默认值。


  2. 开源 JTDS SQL Server 驱动程序比Microsoft的方式更好。除非有一个最重要的原因,否则改用它。把它放在你的tomcat / lib文件夹中的唯一原因是如果你声明一个


  3. > JTDS的JDBC URL为: jdbc:jtds:sqlserver:// hostname / databasename


  4. JTDS的连接驱动程序类是: net.sourceforge.jtds.jdbc.Driver



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?

解决方案

  1. The context.xml in your web application's META-INF folder will take precedence over the one in the /conf directory, which is really just a generic default.

  2. 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.

  3. The JDBC URL for JTDS is: jdbc:jtds:sqlserver://hostname/databasename

  4. The connection driver class for JTDS is: net.sourceforge.jtds.jdbc.Driver

这篇关于无法为连接URL'null'创建类''的JDBC驱动程序:Tomcat&amp; SQL Server JDBC驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆