<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>连接MySql数据库</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
//建立连接
Connection conn= DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/student","root","444444");
//创建语句对象
Statement stmt=conn.createStatement();
String sql="select * from demo";
ResultSet rs=stmt.executeQuery(sql);
//rs.first();
while(rs.next()){
//在控制台输出
System.out.println(rs.getString(1)+"\t"+rs.getInt(2));
//在浏览器输出
out.write(rs.getString(1)+"\t"+rs.getInt(2));
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>