jsp串連sybase資料庫中文顯示問題終極解決辦法!

來源:互聯網
上載者:User

作者 滿勝
這兩天被如題的問題纏繞,好不容易解決掉了
當時遇到的問題如下:
sybase運行在unix上,編碼未知,jsp頁面顯示查詢資料中文亂碼
pageEncoding和charset都已設定,tomcat的xml檔案也已設定
已經試過的辦法有:
1.  String temp = rsSearch.getString(a[i]);
    if (temp != null) {
    byte[] b = temp.getBytes ("8859_1");
    temp = new String(b,"GBK");
    out.print(temp);
    }
2.String temp = rsSearch.getString(a[i]);

      byte[] buffer = new byte[temp.length()];
      int j=0;
      for (int i = 0; i<temp.length(); i++)
      {
        if (temp.charAt(i)>=0x100)
        {
        char c = temp.charAt(i);
        byte[] buf = (""+c).getBytes();
        buffer[j++] = (byte)buf[0];
        buffer[j++] = (byte)buf[1];
        }
       else
       {
       buffer[j++] = (byte)temp.charAt(i);
       }
    }
     temp= new String(buffer, 0, j);
為什麼這些用在mysql等資料庫就有效方法用在sybase上就無效
原因是sybase的串連跟其它jdbc連資料庫有不同,需在串連時註明屬性,dbURL 設為
jdbc:sybase:Tds:hostname:port/dbname?charset=eucgb&jconnect_version=4
,比如我的資料庫charset=cp850 ,jconnect_version=3根據自己的情況適當更改就可以了
另外,在jsp頁面需要用到我最開始提到的方法1,至此,中文問題得到解決!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.