Home > database >  Eclipse have null pointer exception connect the mysql database
Eclipse have null pointer exception connect the mysql database

Time:09-24

When writing a JSP file to connect to the database, have null pointer exception, unable to connect to the database, himself, for beginners to find on the Internet for a long time has not been solved, the great spirit guide
genuflect is beggedThe JSP file content is as follows:
& lt; %
String url="JDBC: mysql://localhost/ch10";
String userName="root";
String password="123456";
Connection conn=null;
Try {
Class.forName("com.mysql.jdbc.Driver");
} the catch (a ClassNotFoundException e) {

Out.println (" abnormal "when loading driver class);
} to try {
Conn=null;
Conn=DriverManager. GetConnection (url, userName, password);
} the catch (SQLException e) {
Out.println (" appear in the process of the connect to the database SQL exceptions ");
} the if (conn==null)
Out.println (" connect to the database failed ");
The else
Out.println (" connect to the database success ");
Try {
conn.close();
} the catch (SQLException e) {
Out.println (" close the abnormal SQL database connection ");
}
% & gt;

Error:
Java. Lang. NullPointerException
The at org. Apache. JSP. Testconnection_jsp. _jspService (testconnection_jsp. Java: 92)
The at org. Apache. Jasper. Runtime. HttpJspBase. Service (HttpJspBase. Java: 70)
The at javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 728)
At org. Apache. Jasper. Servlet. JspServletWrapper. Service (432) JspServletWrapper. Java:
The at org. Apache. Jasper. Servlet. JspServlet. ServiceJspFile (JspServlet. Java: 390)
At org. Apache. Jasper. Servlet. JspServlet. Service (334) JspServlet. Java:
The at javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 728)
The at org. Apache. Catalina. Core. ApplicationFilterChain. InternalDoFilter (ApplicationFilterChain. Java: 305)
The at org. Apache. Catalina. Core. ApplicationFilterChain. DoFilter (ApplicationFilterChain. Java: 210)
The at org. Apache. Catalina. Core. StandardWrapperValve. Invoke (StandardWrapperValve. Java: 222)
The at org. Apache. Catalina. Core. StandardContextValve. Invoke (StandardContextValve. Java: 123)
The at org. Apache. Catalina. The authenticator. AuthenticatorBase. Invoke (AuthenticatorBase. Java: 472)
The at org. Apache. Catalina. Core. StandardHostValve. Invoke (StandardHostValve. Java: 171)
The at org. Apache. Catalina. Valves. ErrorReportValve. Invoke (ErrorReportValve. Java: 99)
The at org. Apache. Catalina. Valves. AccessLogValve. Invoke (AccessLogValve. Java: 953)
The at org. Apache. Catalina. Core. StandardEngineValve. Invoke (StandardEngineValve. Java: 118)
At org. Apache. Catalina. Connector. CoyoteAdapter. Service (408) CoyoteAdapter. Java:
The at org. Apache. Coyote. Http11. AbstractHttp11Processor. Process (AbstractHttp11Processor. Java: 1008)
The at org. Apache. Coyote. AbstractProtocol $AbstractConnectionHandler. Process (AbstractProtocol. Java: 589)
At org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run JIoEndpoint. Java: (310)
The at Java. Util. Concurrent. ThreadPoolExecutor. RunWorker (Unknown Source)
The at Java. Util. Concurrent. ThreadPoolExecutor $Worker. The run (Unknown Source)
The at Java. Lang. Thread. The run (Unknown Source)




Org. Apache. Jasper. JasperException: Java. Lang. NullPointerException
Org. Apache. Jasper. Servlet. JspServletWrapper. HandleJspException (JspServletWrapper. Java: 549)
Org. Apache. Jasper. Servlet. JspServletWrapper. Service (470) JspServletWrapper. Java:
Org. Apache. Jasper. Servlet. JspServlet. ServiceJspFile (JspServlet. Java: 390)
Org. Apache. Jasper. Servlet. JspServlet. Service (334) JspServlet. Java:
Javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 728)



Root cause
Java. Lang. NullPointerException
Org. Apache. JSP. Testconnection_jsp. _jspService (testconnection_jsp. Java: 92)
Org. Apache. Jasper. Runtime. HttpJspBase. Service (HttpJspBase. Java: 70)
Javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 728)
Org. Apache. Jasper. Servlet. JspServletWrapper. Service (432) JspServletWrapper. Java:
Org. Apache. Jasper. Servlet. JspServlet. ServiceJspFile (JspServlet. Java: 390)
Org. Apache. Jasper. Servlet. JspServlet. Service (334) JspServlet. Java:
Javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 728)

CodePudding user response:

I am here to learn!



Obviously it didn't write in your url port number;


String url="JDBC: mysql://localhost/ch10";


MySQL port number is 3306;

The String url="JDBC: mysql://localhost: 3306/ch10";

CodePudding user response:

String url="JDBC: mysql://localhost/ch10";
String userName="root";
String password="123456";

You according to your this link first string, use the mysql client directly try log in to mysql, and see if I can log on?

CodePudding user response:

Add port number is still unable to run, or a null pointer exception

CodePudding user response:

User name password can go to, have no problem

CodePudding user response:

Port, is also a null pointer, a null pointer, the general is null, call the method is to null object, from the perspective of the application of has written, does not seem to be null calls, but whether it is in. The JSP or. All you need to import the Java file write JDBC related packages
In Java import "Java. SQL. *
And JSP in the front lines need to add instructions
& lt; % @ page language="Java" import=" Java. SQL. * "pageEncoding=" utf-8 "% & gt;
So I guess is less & lt; % @ page language="Java" import=" Java. SQL. * "pageEncoding=" utf-8 "% & gt; ,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related