在Java Web这快,客户端获取数据库的数据时,报服务器内部错误。(驱动和数据库都是一致的,是8.0.26的版本)该怎么解决嘞!
报错如下:
HTTP状态 500 - 内部服务器错误
类型 异常报告
消息 Cannot invoke "java.sql.Connection.prepareStatement(String, int)" because "this.conn" is null
描述 服务器遇到一个意外的情况,阻止它完成请求。
例外情况
java.lang.NullPointerException: Cannot invoke "java.sql.Connection.prepareStatement(String, int)" because "this.conn" is null
com.example.fruit.dao.base.BaseDAO.executeUpdate(BaseDAO.java:86)
com.example.fruit.dao.impl.FruitDAOImpl.addFruit(FruitDAOImpl.java:19)
com.example.javawebdemo1.AddServlet.doPost(AddServlet.java:29)
javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
):注意 主要问题的全部 stack 信息可以在 server logs 里查看
idea报错如下:
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1415)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1223)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at com.example.fruit.dao.base.BaseDAO.getConn(BaseDAO.java:45)
at com.example.fruit.dao.base.BaseDAO.executeUpdate(BaseDAO.java:84)
at com.example.fruit.dao.impl.FruitDAOImpl.addFruit(FruitDAOImpl.java:19)
at com.example.javawebdemo1.AddServlet.doPost(AddServlet.java:29)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
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:196)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:366)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:639)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:847)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1680)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)
数据库连接配置:
public final String DRIVER = "com.mysql.cj.jdbc.Driver" ;
public final String URL = "jdbc:mysql://localhost:3306/fruitdb"
public final String USER = "root";
public final String PWD = "123456" ;