JSP connected Sybase database Chinese display problem Ultimate solution!

Source: Internet
Author: User
Tags sybase sybase database
js| Solution | data | database | problem | show | Chinese

The author is full of victory

These two days by the title of the problem entangled, and finally solved the

The problems encountered at that time were as follows:

Sybase running on UNIX, code unknown, JSP page display query data Chinese garbled
Pageencoding and CharSet are set, Tomcat's XML file is also set
The methods that have been tried are:
1. The 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 these are effective methods used in databases such as MySQL are not valid for Sybase

The reason is that the Sybase connection is different from the other JDBC database, and it needs to be marked with attributes when connected, Dburl set to

Jdbc:sybase:tds:hostname:port/dbname?charset=eucgb&jconnect_version=4

, such as my database charset=cp850, jconnect_version=3 according to their own situation to change the appropriate

In addition, the JSP page need to use the method I mentioned at the beginning of 1, so far, the Chinese problem is resolved!




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.