The ultimate solution to the problem of jsp connection to sybase database Chinese display!

Source: Internet
Author: User
Tags sybase sybase database

Author Mansheng
These two days have been entangled in problems such as questions, so it is hard to solve them.
The problems encountered at the time were as follows:
Sybase runs on unix, the encoding is unknown, and the query data is garbled in Chinese on the jsp page.
Both pageEncoding and charset are set, and the xml file of tomcat is also set.
You have tried the following methods:
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 );
Why are these effective methods used in databases such as mysql used in sybase?
The reason is that the sybase connection is different from other jdbc connection databases. You need to specify the attribute during the connection, and dbURL is set
Jdbc: sybase: Tds: hostname: port/dbname? Charset = eucgb & jconnect_version = 4
For example, my database charset = cp850 and jconnect_version = 3 can be changed as needed.
In addition, I need to use method 1 I mentioned at the beginning on the jsp page. Now, the Chinese problem has been solved!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.