tomcat 上部署的 Web 服务无法访问远程 SQL 服务器
Remote SQL Server is not reachable for web service deployed on tomcat
我在 Centos 7 OS 上安装了一个 tomcat 服务器,并且我在上面部署了一个网络服务。
Web 服务必须连接到位于 windows 服务器中的 SQL 服务器。 Centos 已从 windows 服务器 ping 通。 telnet return 也已连接。但是,如果我调用 Web 服务对数据库(创建、更新、删除)执行某些操作,它将 return 内部错误作为响应。
但是当我在 Tomcat 上部署我的 Web 服务项目时,它安装在 windows OS 上,它没有问题。我不知道该怎么办。
public class JDBCConnection {
private static final String DB_DRIVER_CLASS = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static final String DB_URL = "jdbc:sqlserver://192.168.X.X:1433;databaseName=DB_Name";
private static final String DB_USERNAME = "username";
private static final String DB_PASSWORD = "password";
我还尝试了 SQL 服务器的外部 IP 地址:
public class JDBCConnection {
private static final String DB_DRIVER_CLASS = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static final String DB_URL = "jdbc:sqlserver://77.238.X.X:1433;databaseName=DB_Name";
private static final String DB_USERNAME = "username";
private static final String DB_PASSWORD = "password";
错误:
<body>
<h1>HTTP Status 500 – Internal Server Error</h1>
<hr class="line" />
<p><b>Type</b> Exception Report</p>
<p><b>Message</b> java.lang.NullPointerException</p>
<p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.
</p>
<p><b>Exception</b></p>
<pre>javax.servlet.ServletException: java.lang.NullPointerException
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:432)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</pre>
<p><b>Root Cause</b></p>
<pre>java.lang.NullPointerException
com.comment.doa.siteService.getAllCommentsService(siteService.java:106)
com.comment.service.siteResource.getAllComments(siteResource.java:51)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static[=14=](ResourceMethodInvocationHandlerFactory.java:76)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.run(AbstractJavaResourceMethodDispatcher.java:148)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191)
org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:243)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103)
org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493)
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415)
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:104)
org.glassfish.jersey.server.ServerRuntime.run(ServerRuntime.java:277)
org.glassfish.jersey.internal.Errors.call(Errors.java:272)
org.glassfish.jersey.internal.Errors.call(Errors.java:268)
org.glassfish.jersey.internal.Errors.process(Errors.java:316)
org.glassfish.jersey.internal.Errors.process(Errors.java:298)
org.glassfish.jersey.internal.Errors.process(Errors.java:268)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</pre>
<p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p>
<hr class="line" />
<h3>Apache Tomcat/8.5.54</h3>
</body>
</html>
问题是 tomcat lib 目录中缺少一个 jar 文件:sqljdbc42.jar
我在 Centos 7 OS 上安装了一个 tomcat 服务器,并且我在上面部署了一个网络服务。
Web 服务必须连接到位于 windows 服务器中的 SQL 服务器。 Centos 已从 windows 服务器 ping 通。 telnet return 也已连接。但是,如果我调用 Web 服务对数据库(创建、更新、删除)执行某些操作,它将 return 内部错误作为响应。 但是当我在 Tomcat 上部署我的 Web 服务项目时,它安装在 windows OS 上,它没有问题。我不知道该怎么办。
public class JDBCConnection {
private static final String DB_DRIVER_CLASS = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static final String DB_URL = "jdbc:sqlserver://192.168.X.X:1433;databaseName=DB_Name";
private static final String DB_USERNAME = "username";
private static final String DB_PASSWORD = "password";
我还尝试了 SQL 服务器的外部 IP 地址:
public class JDBCConnection {
private static final String DB_DRIVER_CLASS = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static final String DB_URL = "jdbc:sqlserver://77.238.X.X:1433;databaseName=DB_Name";
private static final String DB_USERNAME = "username";
private static final String DB_PASSWORD = "password";
错误:
<body>
<h1>HTTP Status 500 – Internal Server Error</h1>
<hr class="line" />
<p><b>Type</b> Exception Report</p>
<p><b>Message</b> java.lang.NullPointerException</p>
<p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.
</p>
<p><b>Exception</b></p>
<pre>javax.servlet.ServletException: java.lang.NullPointerException
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:432)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</pre>
<p><b>Root Cause</b></p>
<pre>java.lang.NullPointerException
com.comment.doa.siteService.getAllCommentsService(siteService.java:106)
com.comment.service.siteResource.getAllComments(siteResource.java:51)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static[=14=](ResourceMethodInvocationHandlerFactory.java:76)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.run(AbstractJavaResourceMethodDispatcher.java:148)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191)
org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:243)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103)
org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493)
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415)
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:104)
org.glassfish.jersey.server.ServerRuntime.run(ServerRuntime.java:277)
org.glassfish.jersey.internal.Errors.call(Errors.java:272)
org.glassfish.jersey.internal.Errors.call(Errors.java:268)
org.glassfish.jersey.internal.Errors.process(Errors.java:316)
org.glassfish.jersey.internal.Errors.process(Errors.java:298)
org.glassfish.jersey.internal.Errors.process(Errors.java:268)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</pre>
<p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p>
<hr class="line" />
<h3>Apache Tomcat/8.5.54</h3>
</body>
</html>
问题是 tomcat lib 目录中缺少一个 jar 文件:sqljdbc42.jar