When Java reads Oracle and encounters Chinese garbled characters, we need to transcode. (Recommended:java video tutorial)
Transcoding method:
1. Pure manual transcoding
Convert the read string s Code, such as: new String(s.getByte(A), B)
2, Druid
druid is a driver developed by Alibaba itself. It is actually a driver for various databases. It provides a unified layer of encapsulation and adds functions such as logs, alarms, and code conversion. The configuration method is as follows:
serverEncoding=ISO-8859-1;clientEncoding=GBK;defaultRowPrefetch=50;bigStringTryClob=true
The connectionProperties contains two properties: serverEncoding and clientEncoding. After Java reads the data, if it is found that serverEncoding and clientEncoding are different, the following encoding conversion will be automatically performed.
new String(s.getByte(serverEncoding), clientEncoding)
For more java knowledge, please pay attention to thejava basic tutorialcolumn.
The above is the detailed content of Solution to Java reading oracle garbled code. For more information, please follow other related articles on the PHP Chinese website!