Home > Back-end >  Abnormal eclipse JSP to connect the mysql database
Abnormal eclipse JSP to connect the mysql database

Time:09-27

Eclipse JSP to connect the mysql database is what will display abnormal, the data table show not to come out, the code is as follows:
<% @ page language="Java" contentType="text/HTML. Charset=utf-8 "
PageEncoding="utf-8" % & gt;
<% @ page import="Java. SQL. *" % & gt;
<% @ page import="Java. SQL. Connection" % & gt;
<% @ page import="Java. SQL. DriverManager" % & gt;
<% @ page import="Java, SQL Statement" % & gt;



<meta charset="utf-8" & gt;
Insert the title here

<body>
<%
Try {
Class.forName("com.mysql.jdbc.Driver"); Load database drivers////
The String url="JDBC: MySQL://localhost: 3306/RUNOOB? & UseSSL=false& ServerTimezone=UTC ";//points to the database table1
String username="root";//database user name
String password="970613";//database user password
The Connection conn=DriverManager. GetConnection (url, username, password);//connect to the database
If (conn!=null) {
Out. Print (" database connection success!" );
Out.println (" & lt; Br/& gt;" );
Out.println (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - ");
Out. Print (" & lt; Br/& gt;" );
The Statement STMT=null;
The ResultSet rs=null;
String SQL="select * from websites";//query
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
Out.println (" execution results as follows: ");
Out.println (" & lt; Br/& gt;" );
Out.println (" & lt; Br/& gt;" );
Out.println (" serial number "+" \ t "+" name "+" \ t "+" address "+" \ t "+" ranking "+" \ t "+" country ");
Out.println (" & lt; Br/& gt;" );
While (rs), next ()) {
Out.println (rs. Get int (" serial number ") + rs. Get string (" name ") + "& amp; NBSP "+ rs. Get string (" address") + "& amp; NBSP "+ rs. Get int (" ranking") + "& amp; NBSP "+ rs. Get string (" state"));//the database table query result output
Out. Print (" & lt; Br/& gt;" );
}
}
The else {
Out. Print (" connection failed!" );
}
}
/* the try {
If (rs!=null) rs. The close ();
If (STMT!=null) STMT. Close ();
If (connection!=null) connection. The close ();
} */
The catch (Exception e) {
Out. Print (" database connection exception!" );
}



% & gt;




The results are as follows:

The database connection success!
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The results as follows:

Number, name and address in country
Database connection exception!

CodePudding user response:

//you output database connection exception
 
The catch (Exception e) {
//this place the abnormal output and see exactly what is wrong, then see how to solve the
e.printStackTrace();

Out. Print (" database connection exception!" );

}

CodePudding user response:

Make a proposal to try one line, move down, one line, you try all ate all wrong on the whole package, who know where is wrong, for example, your password is wrong he submitted to the database connection is unusual, how do I know you password right

CodePudding user response:

You put the Exception e e information under print

CodePudding user response:

Can you tell me the solution
  • Related