<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>中文测试页面</title>
</head>
<body>
<%!
final String dbDriver = "com.mysql.jdbc.Driver" ;
final String dbUrl = "jdbc:mysql://localhost:3306/dbtest" ;
final String dbUser = "root" ;
final String dbPassword = "123456" ;
Connection conn ;
//PreparedStatement prepStmt ;
Statement stmt ;
%>
<%
try {
Class.forName(dbDriver) ;
conn = DriverManager.getConnection(dbUrl,dbUser,dbPassword) ;
String sql = "insert into books(id,name) values('3','中国')" ;
stmt = conn.createStatement() ;
stmt.executeUpdate(sql) ;
//prepStmt = conn.prepareStatement(sql) ;
//prepStmt.setString(2,"这是一个中文测试") ;
//prepStmt.setString(3,"显示就表明测试正确") ;
//prepStmt.executeUpdate() ;
//prepStmt.close() ;
%>
<table border=1 width=400>
<tr >
<td>id</td>
<td>name</td>
</tr>
<%
ResultSet rs = stmt.executeQuery("select * from books") ;
while(rs.next()) {
String id = rs.getString(1) ;
String name = rs.getString(2);
%>
<tr>
<td><%=id%></td>
<td><%=name%></td>
</tr>
<%
}
%>
</table>
<%
rs.close() ;
stmt.close() ;
conn.close() ;
}catch(Exception e) {
out.println("失败");
e.printStackTrace();
}
%>
</body>
</html>
|