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!