当前页面: 开发资料首页 → J2EE 专题 → 我的Mysql5.0中文乱码解决方案
摘要:
create database admin;
use admin;
CREATE TABLE admin (
admin_name char(20) NOT NULL,
admin_password char(20) NOT NULL
) TYPE=MyISAM,
default character set gbk;
<%@ page contentType="text/html; charset=gbk" language="java" import="java.sql.*" import="java.io.*" %>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver");
conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/admin?user=root&password=123456&useUnicode=true&characterEncoding=gbk");
Statement stmt=conn.createStatement();
ResultSet rs=null;
%>
<head>
</head>
<body>
<table width="314" height="34" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#6666FF">
<tr>
<td align="center" height="19" width="100" style="font-size:10pt;color:red;">帐号</td>
<td align="center" height="19" width="40" style="font-size:10pt;color:red;">密码</td>
</tr>
<%
String temp = "insert into admin(admin_name,admin_password) values('你们好','123')";
PreparedStatement pst = conn.prepareStatement(temp);
pst.executeUpdate();
pst.close();
//结束
temp = "select * from admin";
rs=stmt.executeQuery(temp);
while(rs.next()){
String admin=rs.getString("admin_name");
String pass=rs.getString("admin_password");
%>
<tr>
<td align="center" height="19" width="100" style="font-size:10pt;color:blue;"><%=admin%></td>
<td align="center" height="19" width="40" style="font-size:10pt;color:blue;"><%=pass%></td>
</tr>
<%
}
%>
<%
rs.close();
stmt.close();
conn.close();
%>
<tr>
<td height="19" colspan="4" align="center" style="font-size:10pt;color:red;"> </td>
</tr>
</table>
</body>