我正在尝试在Tomcat 8.5上运行的Java servlet和在SQL Server 2012上运行的数据库之间建立连接。
以下是我到目前为止所做的事情:
我在JAVA项目中添加了连接器 sqljdbc42.jar ,
还将同一文件复制到 C:\ Program Files(x86)\ Apache Software Foundation \ Tomcat 8.5 \ lib ,
使用以下替代方法使用连接字符串(在Java代码中):
final String DB_URL="jdbc:microsoft:sqlserver://DBServer\\Instance1:1433;DatabaseName=" +
DB_Name + ";user=" + USER + ";password=" + PASS ;
和
final String DB_URL="jdbc:sqlserver://DBServer\\Instance1:1433;DatabaseName=" +
DB_Name + ";user=" + USER + ";password=" + PASS ;
我仍然收到以下错误:
SQLException: No suitable driver found for jdbc:sqlserver://DBServer\Instance1:1433;DatabaseName=MyDB;user=Web_Client;password=PWPWPWPW [Ljava.lang.StackTraceElement;@1bd336e
And the error stack is:
java.sql.SQLException: No suitable driver found for jdbc:jdbc:sqlserver://DBServer\Instance1:1433;DatabaseName=MyDB;user=Web_Client;password=PWPWPWPW at
java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at
DispatcherClass.doGet(DispatcherClass.java:72) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:622) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474) at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) at
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783) at
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798) at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434) at
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at
java.lang.Thread.run(Unknown Source)
我既不熟悉Java(使用Eclipse创建WAR)也不熟悉Tomcat。