<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="java.sql.*"%>
<%
String DRIVER = "com.mysql.jdbc.Driver"; // 数据库驱动程序
String USER = "root"; // 数据库用户名
String PASSWORD = "root"; // 数据库连接密码
String URL = "jdbc:mysql://localhost:3306/books?user=" + USER
+ "&password=" + PASSWORD
+ "&useUnicode=true&characterEncoding=GB2312"; // 数据库连接地址
//student是数据库的名字
String sql = "select * from users";//这个是数据库中表的名字
try {
Class.forName(DRIVER).newInstance();
Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
out.print("<br>用户名:" + rs.getString(2));//+ "年龄" + rs.getInt(3));
}
out.print("数据库操作成功,恭喜你");
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
System.out.println("数据库连接不成功" + e.toString());
}
%>