Java 如何解决:找不到适合 sqlserver://localhost:1433;DatabaseName=XX 的驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20447545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix: No suitable driver found for sqlserver://localhost:1433;DatabaseName=XX
提问by Jalle
I have huge Java project that fails to run because of this database error
由于此数据库错误,我有一个巨大的 Java 项目无法运行
APPLICATION STARTUP FAILURE No suitable driver found for sqlserver://localhost:1433;DatabaseName=XX java.sql.SQLException: No suitable driver found for sqlserver://localhost:1433;DatabaseName=XX at java.sql.DriverManager.getConnection(DriverManager.java:602) at java.sql.DriverManager.getConnection(DriverManager.java:185) at artemispm.serverutil.ConnectionPool.newConnection(ConnectionPool.java:577) at artemispm.serverutil.ConnectionPool.manageConnections(ConnectionPool.java:470) at artemispm.serverutil.ConnectionPool.getPooledConnection(ConnectionPool.java:421) at artemispm.serverutil.ConnectionPool.getConnection(ConnectionPool.java:355) at artemispm.serverutil.ConnectionPool.getConnection(ConnectionPool.java:329) at artemispm.serverutil.AppMgr.getConnection(AppMgr.java:492) at artemispm.trjdbc.TRJConnection.(TRJConnection.java:46) at artemispm.trdo.TRBaseSql.getConnection(TRBaseSql.java:2903) at artemispm.service.TRDebugWriter.transmit(TRDebugWriter.java:105) at artemispm.trapplets.DataBroker.clockedTransmit(DataBroker.java:4969) at artemispm.trapplets.DataBroker.callService(DataBroker.java:3125) at artemispm.trapplets.DataBroker.callService(DataBroker.java:3103) at artemispm.trapplets.DataBroker.initTriton(DataBroker.java:325) at artemispm.trapplets.TRApplet.init(TRApplet.java:296) at sun.applet.AppletPanel.run(AppletPanel.java:425) at java.lang.Thread.run(Thread.java:662)
Build Version:?VERSION? productpm.trdo.TRSeriousException: No suitable driver found for sqlserver://localhost:1433;DatabaseName=XX at artemispm.trapplets.DataBroker.checkError(DataBroker.java:659) at artemispm.trapplets.DataBroker.callService(DataBroker.java:3129) at artemispm.trapplets.DataBroker.callService(DataBroker.java:3103) at artemispm.trapplets.DataBroker.initTriton(DataBroker.java:325) at artemispm.trapplets.TRApplet.init(TRApplet.java:296) at sun.applet.AppletPanel.run(AppletPanel.java:425) at java.lang.Thread.run(Thread.java:662)
应用程序启动失败找不到适用于 sqlserver://localhost:1433 的驱动程序;DatabaseName=XX java.sql.SQLException:未找到适用于 sqlserver://localhost:1433 的驱动程序;DatabaseName=XX 在 java.sql.DriverManager.getConnection( DriverManager.java:602) at java.sql.DriverManager.getConnection(DriverManager.java:185) at artemispm.serverutil.ConnectionPool.newConnection(ConnectionPool.java:577) at artemispm.serverutil.ConnectionPool.manageConnections(ConnectionPool.java:470) ) at artemispm.serverutil.ConnectionPool.getPooledConnection(ConnectionPool.java:421) at artemispm.serverutil.ConnectionPool.getConnection(ConnectionPool.java:355) at artemispm.serverutil.ConnectionPool.getConnection(ConnectionPool.java:329) at artemispm.serverutil .AppMgr.getConnection(AppMgr.java:492) 在 artemispm。trjdbc.TRJConnection.(TRJConnection.java:46) at artemispm.trdo.TRBaseSql.getConnection(TRBaseSql.java:2903) at artemispm.service.TRDebugWriter.transmit(TRDebugWriter.java:105) at artemispm.trapplets.DataBroker.clockedTransmit( DataBroker.java:4969) at artemispm.trapplets.DataBroker.callService(DataBroker.java:3125) at artemispm.trapplets.DataBroker.callService(DataBroker.java:3103) at artemispm.trapplets.DataBroker.initTriton(DataBroker.java) ) at artemispm.trapplets.TRApplet.init(TRApplet.java:296) at sun.applet.AppletPanel.run(AppletPanel.java:425) at java.lang.Thread.run(Thread.java:662)trapplets.DataBroker.clockedTransmit(DataBroker.java:4969) at artemispm.trapplets.DataBroker.callService(DataBroker.java:3125) at artemispm.trapplets.DataBroker.callService(DataBroker.java:3103) at artemispm.trapplets.callService(DataBroker.java:3125) (DataBroker.java:325) at artemispm.trapplets.TRApplet.init(TRApplet.java:296) at sun.applet.AppletPanel.run(AppletPanel.java:425) at java.lang.Thread.run(Thread.java:第662章)trapplets.DataBroker.clockedTransmit(DataBroker.java:4969) at artemispm.trapplets.DataBroker.callService(DataBroker.java:3125) at artemispm.trapplets.DataBroker.callService(DataBroker.java:3103) at artemispm.trapplets.callService(DataBroker.java:3125) (DataBroker.java:325) at artemispm.trapplets.TRApplet.init(TRApplet.java:296) at sun.applet.AppletPanel.run(AppletPanel.java:425) at java.lang.Thread.run(Thread.java:第662章)Thread.run(Thread.java:662)Thread.run(Thread.java:662)
构建版本:?版本?productpm.trdo.TRSeriousException: 在 artemispm.trapplets.DataBroker.checkError(DataBroker.java:659) at artemispm.trapplets.DataBroker.callService(DataBroker.java: 3129) at artemispm.trapplets.DataBroker.callService(DataBroker.java:3103) at artemispm.trapplets.DataBroker.initTriton(DataBroker.java:325) at artemispm.trapplets.TRApplet.init(TRApplet.java:296) at sun. applet.AppletPanel.run(AppletPanel.java:425) 在 java.lang.Thread.run(Thread.java:662)
I tried to placing sqljdbc.jar sqljdbc4.jar in %catalina_home&\lib folder but that did not help
我试图将 sqljdbc.jar sqljdbc4.jar 放在 %catalina_home&\lib 文件夹中,但这没有帮助
I am not familiar with Java but would appreciate any help on this.
我不熟悉 Java,但希望得到任何帮助。
EDIT: My connections string is defined in customer.properties file like this: APP.url= sqlserver://localhost:1433;DatabaseName=XX
编辑:我的连接字符串在 customer.properties 文件中定义如下:APP.url= sqlserver://localhost:1433;DatabaseName=XX
Now I changed it to: APP.url= jdbc:sqlserver://localhost:1433;DatabaseName=XX
现在我改成:APP.url= jdbc:sqlserver://localhost:1433;DatabaseName=XX
and I have new error:
我有新的错误:
APPLICATION STARTUP FAILURE Java Runtime Environment (JRE) version 1.6 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
应用程序启动失败 此驱动程序不支持 Java 运行时环境 (JRE) 1.6 版。使用 sqljdbc4.jar 类库,它提供对 JDBC 4.0 的支持。
How do I switch to new driver ?
如何切换到新驱动程序?
采纳答案by Anhil
Your URL should be jdbc:sqlserver://server:port;DatabaseName=dbname
.
您的网址应该是jdbc:sqlserver://server:port;DatabaseName=dbname
.
Are you sure that you typed it correctly?
你确定你输入正确吗?
回答by user2749982
From sqljdbc_4.0 documentation (http://technet.microsoft.com/en-us/library/ms378526(v=sql.110).aspx):
来自 sqljdbc_4.0 文档(http://technet.microsoft.com/en-us/library/ms378526(v=sql.110).aspx):
Using the sqljdbc.jar class library, applications must first register the driver as follows: Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); When the driver is loaded, you can establish a connection by using a connection URL and the getConnection method of the DriverManager class:
使用 sqljdbc.jar 类库,应用程序必须首先注册驱动程序如下: Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 驱动加载完成后,可以通过连接 URL 和 DriverManager 类的 getConnection 方法建立连接:
When the getConnection method of the DriverManager class is called, an appropriate driver is located from the set of registered JDBC drivers. sqljdbc4.jar file includes "META-INF/services/java.sql.Driver" file, which contains the com.microsoft.sqlserver.jdbc.SQLServerDriver as a registered driver. The existing applications, which currently load the drivers by using the Class.forName method, will continue to work without modification.
当调用 DriverManager 类的 getConnection 方法时,会从已注册的 JDBC 驱动程序集中找到合适的驱动程序。sqljdbc4.jar 文件包括“META-INF/services/java.sql.Driver”文件,其中包含 com.microsoft.sqlserver.jdbc.SQLServerDriver 作为注册驱动程序。当前使用 Class.forName 方法加载驱动程序的现有应用程序将继续工作而无需修改。
回答by sanal
I tried the above answers and they alone didn't help me. I had to try some more.
我尝试了上述答案,但仅靠它们并没有帮助我。我不得不再试一些。
So i tried something else. I copied the "sqljdbc4.jar" file to "C:\apache-tomcat-7.0.57\lib\" and then added "sqljdbc4.jar" to the library of my project. It fixed everything.
所以我尝试了别的东西。我将“sqljdbc4.jar”文件复制到“C:\apache-tomcat-7.0.57\lib\”,然后将“sqljdbc4.jar”添加到我的项目库中。它修复了一切。
I hope this helps those still had trouble.
我希望这可以帮助那些仍然遇到问题的人。
回答by Dulith De Costa
I copied the sqljdbc4.jar
to the lib folder in the Tomcat folder, and also I added it to my project as well. Still I encountered the same exception. Finally after googling heavily I found that the error is with Tomcat.
我将其复制sqljdbc4.jar
到 Tomcat 文件夹中的 lib 文件夹,并将其添加到我的项目中。我仍然遇到了同样的异常。最后,在大量搜索之后,我发现错误出在 Tomcat 上。
Tomcat tries to prevent memory leaks due to sql server driver. To overcome the exception, it need to be disabledso that it would load the driver automatically.
Tomcat 试图防止由于 sql server 驱动程序造成的内存泄漏。为了克服这个异常,它需要被禁用,以便它会自动加载驱动程序。
To disable, change the server.xml
in Tomcat and make "JreMemoryLeakPreventionListener
" marked as FALSE.
要禁用,请更改server.xml
Tomcat 中的 并将“ JreMemoryLeakPreventionListener
”标记为 FALSE。
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" driverManagerProtection="false" />
This helped me to prevent following exception and now it works properly.
这帮助我防止了以下异常,现在它可以正常工作。