0

I have a tomcat server installed in a Centos 7 OS, and also I have deployed a web service on it.

The web service must be connected to a SQL Server which is located in a windows server. The Centos has ping from windows server. the telnet return connected, too. 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. But when I deploy my web service project on a Tomcat which is installed on a windows OS, it has no problem. 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:

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>
Dale K
  • 25,246
  • 15
  • 42
  • 71
M-E
  • 168
  • 4
  • 19
  • can you check the line that has nullpointerexception? com.comment.doa.siteService.getAllCommentsService(siteService.java:106) <- is this in your code? – Erwin May 12 '20 at 12:38
  • @Erwin yes it's where I have PreparedStatement pstmt = checkSqlCon(sqlConnection).prepareStatement(sql); and in sqlconnection I have if (sqlConnection == null) { sqlConnection = jdbcConnection.getSqlConnnection(); } and JDBCCONNECTION is 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"; – M-E May 13 '20 at 14:49
  • This line? -> PreparedStatement pstmt = checkSqlCon(sqlConnection).prepareStatement(sql); Which is null? sqlConnection, sql, or checkSqlCon? What about the stack trace in the server log? – Erwin May 13 '20 at 15:59

1 Answers1

0

The problem was missing a jar file in tomcat lib directory: sqljdbc42.jar

M-E
  • 168
  • 4
  • 19