<%@ page contentType="text/html;charset=GBK" language="java" import="java.sql.*"%>
<html>
<head>
<title></title>
</head>
<body>
<%
try{
//加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
//驱动程序连接到数据库
String dbUrl = "jdbc:mysql://localhost/frm";
String dbUser="root";
String dbPwd ="root";
//建立数据库连接
Connection con = DriverManager.getConnection(dbUrl,dbUser,dbPwd);
Statement stmt = con.createStatement();
//查询记录
ResultSet rs=stmt.executeQuery("SELECT * from test");
//输出查询结果
out.println("<center><table border = 1 width = 400>");
while(rs.next())
{
out.println("<tr>");
out.println("<td>"+rs.getString("id")+"</td>");
out.println("<td>"+rs.getString("book")+"</td>");
out.println("<td>"+rs.getString("name")+"</td>");
out.println("</tr>");
}
out.println("</table></center>");
//关闭数据库接连
rs.close();
stmt.close();
con.close();
}
//捕获错误信息
catch(Exception e){
out.println(e.getMessage());
}
%>
</body>
</html>
我用的jar是mysql-connector-java-3.1.8-bin 有问题吗?运行后显示的是com.mysql.jdbc.Driver