public String strIntoDb(String string)
  {
String str = null;
try{
str = new String(string.getBytes("gb2312"),"ISO8859-1");
}catch(java.io.UnsupportedEncodingException ue) {
}
return str;
   }

解决方案 »

  1.   

    String str = new String(string.getBytes("gb2312"),"ISO8859-1");
    -->
    String str = new String(string.getBytes("ISO8859_1"),"gb2312");
      

  2.   

    谢谢ChDw(米)!
    再问一下,为什么非得抛出这异常?
      

  3.   

    zxhong(红透半边天) :
    两个参数的位置我搞混了,能解释一下吗?
      

  4.   

    因为有可能会出现你所指定的字符集不存在的情况
    所以getBytes,和new String(byte[],enc)都声明
    抛出了UnsupportedEncodingException ,所以你只能catch它
      

  5.   

    其实就是如果你所传入的参数为null时,是不能进行字符转换的,自然会跳出异常。
    new String(change.getBytes("iso-8859-1"),"gb2312")为从数据库中读去;
    new String(change.getBytes("gb2312"),"iso-8859-1")为写入数据库。
    我的数据库为ORACLE,其他数据库是否要进行该操作未进行测试。