试试转码:
String newstring = new String(s.getBytes("gb2312"),"ISO8859_1");
其中,s是你要插入到数据库中的字符串。转换后,把newstring插入数据库。你可以搜索一下“中文”或者“转码”,也许会找到些有用的东西。
String newstring = new String(s.getBytes("gb2312"),"ISO8859_1");
其中,s是你要插入到数据库中的字符串。转换后,把newstring插入数据库。你可以搜索一下“中文”或者“转码”,也许会找到些有用的东西。
解决方案 »
- 有没有现成的方法:取出一个字符串里第三个字符的位置
- 求教有关Runtime问题
- 程序设计
- 正则表达式如何匹配小数
- 大伙帮小弟看看,关于读取文件(一个以逗号分隔的csv文件),初学咋到
- corejava 中的一个sketch程序??高手请进
- 有没有删除JPanel和JLabel的方法啊?
- 运行JAVAC的Application Error
- 关于SQL Server 2000 Driver for JDBC
- 考过SCJP后要过多久才能在 www.galton.com/~sun/ 查到自己的资料啊?(SUN的工作效率好低,已经一周了)
- 如何清空cache
- 如和在dos下只打java或appletviewer反正就是bin文件夹中的程序就运行
其实你就用s.getBytes("gb2312")得到的字节数组写入数据库就行了
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
应该是
jdbc:mysql://[hostname][:port]/dbname?useUnicode=true&characterEncoding=GB2312楼上的兄弟,你的那个方法对于数据库存取不行,因为编码转换部分是在jdbc驱动内完成的,如果不在取数据的时候设置编码为gb2312,jdbc取数据的时候就会按照错误的编码进行编码转换