获取数据源的那段java代码
url使用如下格式
jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=GBK

解决方案 »

  1.   

    1.首先:保证在数据库中保存的文字是中文的。(查看数据库中保存的记录)
    2.其次:保证所输出的页面已经使其为能够显示中文的(设置其contentType)。
    3.如果以上条件均符合,但仍为乱码,那么可以考虑编码转换。
      

  2.   

    建议用编码转换,如下:
    //***************************************************
    //名称:ChangeCode
    //功能:转换指定字符串的字符集(字符编码)
    //输入:strSource: 要转换的字符串; strCodeFrom: 源字符集; strCodeTo: 目的字符集
    //输出:
    //返回:转换之后的字符串
    //***************************************************
    public String ChangeCode(String strSource, String strCodeFrom, String strCodeTo)
    {
    byte[] baTemp = null;
    try
    {
    baTemp = strSource.getBytes (strCodeFrom);
    strSource = new String (baTemp,strCodeTo);
    }
    catch (Exception e)
    {
    return (e.toString ());
    } return (strSource);
    }///
    aStrSql = ChangeCode (aStrSql, "8859_1", "cp850");
      

  3.   

    字符集所使用的编码格式不同,必须要进行编码转换String newStr = s.getBytes("8859_1")
      

  4.   

    1.s=new String(s.getBytes(),"iso-8859-1");
    2.s=new String(s.getBytes(),"gb2312");
    3.s=new String(s.getBytes("iso-8859-1"),"gb2312");
    4.s=new String(s.getBytes("gb2312"),"iso-8859-1");
    5.s=new String(s.getBytes("iso-8859-1"));
    6.s=new String(s.getBytes("gb2312"));
    尝试以上的方法之一!