在vps上部署后,JSP / Java应用程序无法连接到MySQL

时间:2017-06-27 19:41:12

标签: mysql jsp tomcat servlets nullpointerexception

我在jsp / jva中创建了一个动态Web应用程序,并连接到MySQL服务器,该服务器在我的vps上的localhost数据库和数据库上运行。连接类中的代码:

public static Connection con=null;

public static void connection() {

String connectionURL = "jdbc:mysql://<vps ip>:3306/messages";

try {
    Class.forName("com.mysql.jdbc.Driver");
   con = DriverManager.getConnection(connectionURL, "user", "password");
} catch (Exception e) {
    System.out.println("Connection Error");
}

当我尝试http://vps ip:8080 / Messages / CreateMessage时,这是堆栈跟踪输出。但是,当连接到vps上的db时,这适用于http://localhost:8080/Messages/CreateMessage

Message: java.lang.NullPointerException
    at message.jsp.servlet.UpdateMessage.doPost(UpdateMessage.java:293)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    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:478)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    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:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)

我复制了J连接器并将其引用到路径中。有人可以帮帮我吗?

0 个答案:

没有答案