我的JSP头:
<%@ page contentType="text/html; charset=GBK" language="java"%>
我的读出数据库连接:
"jdbc:mysql://localhost:3306/wu?user=root&password=88888881&useUnicode=true&characterEncoding=GBK"
我的写入数据库连接:
"jdbc:mysql://localhost:3306/wu?user=root&password=88888881"1.往表里写入一条中文记录,表里出现"?????"乱码.
2.用mysql直写入一条中文记录没出现乱码,但读出来在页面上又是"?????"乱码.
3.new String(text.getName().getBytes("iso8859-1"),"gbk")从页面的中文又是"????"乱码.总之,真是乱码无处不在,搞得是没有办法.请帮帮忙,谢谢!
<%@ page contentType="text/html; charset=GBK" language="java"%>
我的读出数据库连接:
"jdbc:mysql://localhost:3306/wu?user=root&password=88888881&useUnicode=true&characterEncoding=GBK"
我的写入数据库连接:
"jdbc:mysql://localhost:3306/wu?user=root&password=88888881"1.往表里写入一条中文记录,表里出现"?????"乱码.
2.用mysql直写入一条中文记录没出现乱码,但读出来在页面上又是"?????"乱码.
3.new String(text.getName().getBytes("iso8859-1"),"gbk")从页面的中文又是"????"乱码.总之,真是乱码无处不在,搞得是没有办法.请帮帮忙,谢谢!
cmd模式下用mysql --default-character-set=gbk -u root -p进入
然后再每个建表语句后增加default character set gbk;
重新建立数据表。
public String To8859(String s)
{
String s1 = "";
byte abyte0[] = s.getBytes();
try
{
s1 = new String(abyte0, "8859_1");
}
catch(Exception exception)
{
System.err.println("string code:" + exception.getMessage());
}
return s1;
}
读出之后再转换回来
public String ToCn(String s)
{
String s1 = ""; try
{
byte abyte0[] = s.getBytes("ISO8859_1");
s1 = new String(abyte0, "gb2312");
}
catch(Exception exception)
{
System.err.println("string code:" + exception.getMessage());
}
return s1;
}一般都能解决中文问题