database中文乱码问题

post.jsp
<form method="post" action="addMsg.jsp">
name:<input type=
"text" name="name" >
<input type=
"submit" value="submit">
</form>
<html>
<head>
<title>使用JDBC直接访问数据库</title>
</head>
<%@ page contentType=
"text/html;charset=GB2312" %>
<%@ page import=
"java.sql.*" %>
<%
//String name=new String(request.getParameter("name").getBytes("ISO8859_1"),"GBK");
String name = request.getParameter(
"name");
out.println(name);
Class.forName(
"org.gjt.mm.mysql.Driver");
Connection
con=DriverManager.getConnection(
"jdbc:mysql://localhost/bbs?useUnicode=true&characterEncoding=UTF-8","root","123456");
Statement stmt=con.createStatement();
String sql=
"insert into book(name)values('"+name+"')";
int value;
value=stmt.executeUpdate(sql);
if(value>0)
{
out.println(
"ok");
}
else
{
out.println(
"no");
}
stmt.close();
con.close();
%>
</table>
</body>
</html>
lunzi   2005-11-24 19:33:22 评论:0   阅读:1455   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog