<% @ 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;
<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;