Home Java javaTutorial How to deal with garbled Chinese characters in java oracle

How to deal with garbled Chinese characters in java oracle

Aug 17, 2020 pm 01:49 PM
java oracle Chinese garbled

java Oracle Chinese garbled solution: 1. Convert the read string s manually, the code is [new String(s.getByte(A), B)]; 2. Druid is used to provide a unified layer of encapsulation and encoding conversion for various database drivers.

How to deal with garbled Chinese characters in java oracle

[Related learning recommendations: java basic tutorial]

java oracle Chinese garbled solution:

Transcoding method

When Java reads Oracle and encounters Chinese garbled characters, we need to transcode. There are many methods of transcoding, the ones I have come across are the following.

1. Pure manual transcoding

Transcode the read string s, such as: new String(s.getByte(A), B)

2 , Druid

Druid is a driver developed by Alibaba itself. It actually encapsulates various database drivers in a unified layer, adding functions such as logging, alarms, and encoding 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

3. weblade ibatis callback

It adopts the following method of registering ibatis callback.

<bean id="sqlMapExecutorDelegate"
class="com.asc.alibaba.dao.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate">
<property name="mappedStatementStrategy" ref="mappedStatementStrategy" />
<property name="handlerList">
<list>
<ref bean="stringHandler" />
<!-- <ref bean="objectHandler" />-->
</list>
</property>
</bean>
<bean id="stringHandler" class="com.asc.alibaba.dao.ibatis.handler.TypeHandlerAdapter">
<property name="javaType" value="java.lang.String" />
<property name="handlerCallback" ref="stringTypeHandlerCallback" />
</bean>
Copy after login

So that by default, the program will convert the String obtained by ibatis as follows:

new String(s.getByte(“ISO-8859-1”), “GBK”)
Copy after login

The second-party library is introduced as follows:

<dependency>
<groupId>com.alibaba.asc.shared</groupId>
<artifactId>weblade.core.ibatisext</artifactId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
Copy after login

Ibatis The callback hides the encoding conversion process, but the problem is that it takes effect on all data sources in the project. This makes it impossible to transparently support data sources that require transcoding and data sources that do not require transcoding at the same time.

Related recommendations: Programming video course

The above is the detailed content of How to deal with garbled Chinese characters in java oracle. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to check tablespace size of oracle How to check tablespace size of oracle Apr 11, 2025 pm 08:15 PM

To query the Oracle tablespace size, follow the following steps: Determine the tablespace name by running the query: SELECT tablespace_name FROM dba_tablespaces; Query the tablespace size by running the query: SELECT sum(bytes) AS total_size, sum(bytes_free) AS available_space, sum(bytes) - sum(bytes_free) AS used_space FROM dba_data_files WHERE tablespace_

How to encrypt oracle view How to encrypt oracle view Apr 11, 2025 pm 08:30 PM

Oracle View Encryption allows you to encrypt data in the view, thereby enhancing the security of sensitive information. The steps include: 1) creating the master encryption key (MEk); 2) creating an encrypted view, specifying the view and MEk to be encrypted; 3) authorizing users to access the encrypted view. How encrypted views work: When a user querys for an encrypted view, Oracle uses MEk to decrypt data, ensuring that only authorized users can access readable data.

How to view instance name of oracle How to view instance name of oracle Apr 11, 2025 pm 08:18 PM

There are three ways to view instance names in Oracle: use the "sqlplus" and "select instance_name from v$instance;" commands on the command line. Use the "show instance_name;" command in SQL*Plus. Check environment variables (ORACLE_SID on Linux) through the operating system's Task Manager, Oracle Enterprise Manager, or through the operating system.

How to uninstall Oracle installation failed How to uninstall Oracle installation failed Apr 11, 2025 pm 08:24 PM

Uninstall method for Oracle installation failure: Close Oracle service, delete Oracle program files and registry keys, uninstall Oracle environment variables, and restart the computer. If the uninstall fails, you can uninstall manually using the Oracle Universal Uninstall Tool.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Core Features and Functionality PHP vs. Python: Core Features and Functionality Apr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

See all articles