I rookie a piece ~ ~ ~ Debugging So simple code also adjusted a day, issued to commemorate, of course, I hope to help everyone.
<%@ page contenttype= "text/html" pageencoding= "UTF-8"%<%@ page import= "java.sql.*"%>
<%@ page import= "Java.sql.Connection"%>
<%@ page import= "Java.sql.DriverManager"%>
<body>
<%
Final String dbdriver = "Org.gjt.mm.mysql.Driver";
Final String Dburl = "JDBC:MYSQL://LOCALHOST:3306/MLDN";
Final String DBUSER = "root";
Final String Dbpass = "* * * * *";
%>
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
%>
<%
try{
Class.forName (Dbdriver);
Conn=drivermanager.getconnection (Dburl,dbuser,dbpass);
String sql= "Select Empno,ename,job,sal from emp";
Pstmt=conn.preparestatement (SQL);
Rs=pstmt.executequery ();
%>
<div>
<table border= "1" >
<tr>
<td> numbering </td>
<td> name </td>
<td> work </td>
<td> Wages </td>
</tr>
<%
while (Rs.next ()) {
int Empno=rs.getint (1);
System.out.println (EMPNO);
String ename=rs.getstring (2);
String job=rs.getstring (3);
Float Sal=rs.getfloat (4);
%>
<tr>
<td><%=empno%></td>
<td><%=ename%></td>
<td><%=job%></td>
<td><%=sal%></td>
</tr>
<%
}
%>
</table>
</div>
<%
}catch (Exception e) {
System.out.println (e);
}finally{
Rs.close ();
Pstmt.close ();
Conn.close ();}
%>
</body>
Then the following questions appear:Null pointer exception This problem is still well solved,
To determine whether conn is empty, this is not much to say.
But the runtime still appears error!!! Blank page, the data is not displayed!!!
Only 1.1-point code issue where the problem appears,
Yes, that's it. Print, find the problem, the third line 111 did not print out.
Class.forName ("org.gjt.mm.mysql.Driver"); This is the load database driver,
Then went to find the database-driven file is to be put in, the first local project, the database driver is not put ....
That's right.... Just because the driver didn't put ...
So the driver file is put in, and then go back to MyEclipse to refresh a bit better.
Not everyone will have this problem appear, but I still hope to help everyone, the first time to write a blog, ask the big guy more advice.
MyEclipse An error occurred while connecting to MySQL database, resolve the following