JDBC Chinese processing

zhaozj2021-02-08  455

We are doing a Java application that inevitably handles Chinese. after

Difficult exploration, there are some progress, found some solutions, but still

Faced with a problem that cannot be solved. In this case, I hope to help everyone.

At the same time, please help your questions.

Email: soilor@mailserv.stu.edu.cn

background:

JDK 1.15

VCAFE 2.0

JPadPro

Server:

NT IIS

Sybase system 10

JDBC: JCONNECT

Client:

Browser: Netscape 4.04 Patch

PWIN95 & PWIN98 Beta3

Class files are stored in Server, run applet by Browser, Applet only

The role of Pressing the Frame class main program. The interface includes Text Field, Text Area,

List, choice, etc.

First, take Chinese

Execute the SELECT statement with JDBC After taking the data (Chinese) from Server,

Use the Append method to Text Area (TA) and cannot be displayed correctly. But add to

Most Chinese characters can be displayed correctly when LIST is displayed.

Processing: Press the "ISO-8859-1" format to the byte array, then press the system

The default coding format is converted to String, you can display correctly in TA and LIST.

The segment is as follows:

dbstr2 = results.getstring (1);

// ******************************************************** ********************

// After Read Result From Database Server, Convert the Result String.

DBBYTE1 = dbstr2.getbytes ("ISO-8859-1");

DBSTR1 = New String (dbbyte1);

// ******************************************************** ********************

Second, write Chinese to DB

How to deal with the above phase, first Press the SQL statement by default character encoding

Transfer to byte arrays, press ISO-8859-1 to switch to String, then send execution,

The Chinese information can be written correctly to DB.

SQLSTMT = TF_INPUT.GETTEXT ();

// ******************************************************** ****************************

// Before Send Statement to Database Server, Convert Sql Statement.

Dbbyte1 = SQLSTMT.GETBYTES ();

SQLSTMT = New String (dbbyte1, "ISO-8859-1);

// ******************************************************** ****************************

_stmt = _con.createstatement ();

_stmt.executeUpdate (SQLSTMT);

. . . . . .

problem:

The above method When the local client is existed to the ClassPath point to the Classes of JDK. When ZIP (called A), you can run correctly.

But if the client has only Browser, there is no JDK and ClassPath

(Known as B), the Chinese characters cannot be converted correctly.

Our analysis:

1,

After testing, in A case, the program is running the system's default character.

Encoding = "GBK" OR "GB2312".

In B, the program starts, the Browser's Java Console appears.

The following information:

Can't Find Resource for

Sun.awt.windows.awtlocalization_zh_cn

Systematic

DEFAULT Characterencoding = "8859-1".

2,

If you do not use Default Character Encoding when converting strings,

Instead, "GBK" or "GB2312" is used directly, it is still normal in A.

In B B, the system has an error: UNSUPPORTEDENCODINGEXCEPTION.

3,

On the local client, I put the JDK's classes. After zip decompression, put it on another

In the directory, ClassPath only contains this directory. Then gradually delete the Class in the directory

File, run the test program, finally found in more than 1,000 Class files,

Only one is indispensable, this file is:

Sun.io.ChartobytedoubleByte.Class

I will copy this file to the server and other classes together, and start at the beginning of the program.

Import It is still not normal in B.

4,

In A case, if you go in ClassPth

Sun.io.ChartobytedoubleByte.Class, then the program runs,

Default Character Encoding is "8859-1", otherwise

GBK or GB2312.

5,

Analyze the files in the Browser program Netscape directory

/program/java/classes/java40.jar, found that there is no including

Sun.io.ChartobytedoubleByte.class,

I don't know if this is a need to upgrade, or other methods can be solved?

I hope that everyone guidance! Email: soilor@mailserv.stu.edu.cn

-

※ Source: · BBS Shuimu Tsinghua Station bbs.net.tsinghua.edu.cn · [From: dhcp159_158.stu]

转载请注明原文地址:https://www.9cbs.com/read-879.html

New Post(0)