MyEclipse An error occurred while connecting to MySQL database, resolve the following

Source: Internet
Author: User
Tags blank page

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.