Home > Java > JavaBase > body text

Solution to Java reading oracle garbled code

Release: 2019-12-02 15:25:58
Original
2447 people have browsed it

Solution to Java reading oracle garbled code

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:

<bean id="opensqlDataSource"
		class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="com.alibaba.china.jdbc.SimpleDriver" />
		<property name="url" value="jdbc:oracle:thin:@10.20.130.210:1521:dwtest" />
		<property name="username" value="etl" />
		<property name="password" value="etl" />
		<property name="connectionProperties"><value>serverEncoding=ISO-8859-1;clientEncoding=GBK;defaultRowPrefetch=50;bigStringTryClob=true</value></property>
	</bean>
Copy after login

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)
Copy after login

For more java knowledge, please pay attention to the java basic tutorial column.

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template