[英]Remote SQL Server is not reachable for web service deployed on tomcat
I have a tomcat server installed in a Centos 7 OS, and also I have deployed a web service on it.我在 Centos 7 操作系统中安装了 tomcat 服务器,并且我还在其上部署了 web 服务。
The web service must be connected to a SQL Server which is located in a windows server. web 服务必须连接到位于 windows 服务器中的 SQL 服务器。 The Centos has ping from windows server. Centos 已从 windows 服务器 ping。 the telnet return connected, too. telnet 返回也已连接。 But still, if I call the web service to do something with database(create,update,delete) it will return an internal error as a response.但是,如果我调用 web 服务来处理数据库(创建、更新、删除),它将返回一个内部错误作为响应。 But when I deploy my web service project on a Tomcat which is installed on a windows OS, it has no problem.但是,当我在安装在 windows 操作系统上的 Tomcat 上部署我的 web 服务项目时,它没有问题。 I don't know what should I do.我不知道我该怎么办。
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";
Also I have tried external IP Address for SQL Server:我还尝试了 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";
the error:错误:
<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$0(ResourceMethodInvocationHandlerFactory.java:76)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.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$1.run(ServerRuntime.java:277)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
org.glassfish.jersey.internal.Errors$1.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>
The problem was missing a jar file in tomcat lib directory: sqljdbc42.jar问题是在 tomcat lib 目录中缺少 jar 文件:sqljdbc42.jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.