Home > Database > Mysql Tutorial > body text

Oracle 插入汉字时字符编码问题

WBOY
Release: 2016-06-07 17:00:31
Original
1145 people have browsed it

通过 java PreparedStatement 预编译进入插入操作,跑SQL异常,baidu字符编码问题,经过若干方法转码还是无果,最后变通解决变通

背景:

myeclipse 字符编码  GBK

Oracle数据库字符编码 GBK

插入内容从第三方通过webservice接口取的,字符编码UTF-8

问题描述:

通过 java PreparedStatement 预编译进入插入操作,跑SQL异常,baidu字符编码问题,经过若干方法转码还是无果,最后变通解决

变通解决办法:

通过insert拼接sql语句,因为当前myeclipse环境为GBK编码,,所以拼接后的insert中的汉字即默认转化为GBK编码,插入操作正常。

 拼接SQL如下:

  • 总结

     通过PreparedStatement.setString(index, str);应该是直接连接到数据库,这个过程中的str字符编码还是utf-8,如果不转化,直接  插入数据库跑异常,编码格式不一致。

    通过上述拼接sql,在这个过程中由于变量已经显示在当前环境,这个过程默认转化为GBK格式的,所以再做插入就规避了编码不统一问题,

    但是也没法使用绑定变量来提高性能,不过有时候性能并不是最重要的。

    linux

  • 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
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!