mysql4.1.2的默认字符集是latin1,latin1属于ISO8859-1的子集(或者是一回事?毛深入研究),写入时需要为iso8859-1的编码,读出时要转换成gbk编码,就不会是乱码。
Class.forName("org.gjt.mm.mysql.Driver");
String url ="jdbc:mysql://localhost/mysql";
Connection conn=DriverManager.getConnection(url,"root","root");
Statement stmt=conn.createStatement();
String a="老哈斯蒂芬";
a=new String(a.getBytes("GBK"),"iso8859-1");
stmt.executeUpdate("insert into zquan (name) value ('"+a+"')");
ResultSet rs=stmt.executeQuery("select name from zquan");
while(rs.next()){
String aaa=rs.getString(1);
System.out.println(new String(aaa.getBytes("iso8859-1"),"GB2312"));
}
posted on 2008-11-25 11:12
一凡 阅读(864)
评论(0) 编辑 收藏 所属分类:
DATABASE