GVKun编程网logo

jdbc-mysql 中文乱码解决(jdbc从数据库中读的中文乱码)

1

在这篇文章中,我们将带领您了解jdbc-mysql中文乱码解决的全貌,包括jdbc从数据库中读的中文乱码的相关情况。同时,我们还将为您介绍有关Ajax返回值--中文乱码解决、androidhttppo

在这篇文章中,我们将带领您了解jdbc-mysql 中文乱码解决的全貌,包括jdbc从数据库中读的中文乱码的相关情况。同时,我们还将为您介绍有关Ajax返回值--中文乱码解决、android http post 中文乱码解决、archlinux 中文乱码解决、centos 5.3 中文乱码解决的知识,以帮助您更好地理解这个主题。

本文目录一览:

jdbc-mysql 中文乱码解决(jdbc从数据库中读的中文乱码)

jdbc-mysql 中文乱码解决(jdbc从数据库中读的中文乱码)

在客户端或者JDBC连接时定制支持中文的编码格式(通常使用UTF-8),这样插入数据的时候,让mysql为自动为我们转码,可行的办法有两种:

1、如果是通过DriverManager.getConnection(url)编码方式操作JDBC,可以在JDBC的url中追加useUnicode=true&characterEncoding=UTF-8解决乱码问题

jdbc.url=jdbc:mysql://127.0.0.1:3306/mydb?useUnicode=true&characterEncoding=UTF-8

2、如果是通过其它数据源,比如DBCP、tomcat-jdbc、c3p0、spring-jdbc、hibernate读取配置文件,在url中追加useUnicode=true&characterEncoding=UTF-8是不起作用的,而是通过数据源自身的配置生效,比如下列配置:

<!-- Tomcat data source -->
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
 <property name="driverClassName" value="${jdbc.driverClassName}" />
 <property name="url" value="${jdbc.url}" />
 <property name="username" value="${jdbc.username}" />
 <property name="password" value="${jdbc.password}" />
 <property name="dbProperties">
   <props>
       <prop key="useUnicode">yes</prop>
       <prop key="characterEncoding">utf8</prop>
   </props>
 </property>
 <!-- Configuration refer to optimizing connection performance -->
 <property name="initialSize" value="10" />
 <property name="maxActive" value="100" />
 <property name="maxIdle" value="50" />
 <property name="minIdle" value="10" />
 <property name="suspectTimeout" value="60" />
 <property name="timeBetweenEvictionRunsMillis" value="30000" />
 <property name="minEvictableIdleTimeMillis" value="60000" />
 <property name="testOnBorrow" value="true" />
 <property name="validationQuery" value="SELECT 1" />
 <property name="validationInterval" value="30000" />
 <!-- End Configuration refer to optimizing connection performance -->
</bean>

其中:

<props>
     <prop key="useUnicode">yes</prop>
     <prop key="characterEncoding">utf8</prop>
</props>

等价于url中的useUnicode=true&characterEncoding=UTF-8

Ajax返回值--中文乱码解决

Ajax返回值--中文乱码解决

之前是PrintWriterout=response.getWriter();
response.setContentType("text/xml;charset=UTF-8");
response.setHeader("Cache-Control","no-cache");
这个是写反了的。
应该把 PrintWriterout=response.getWriter(); 放在
之后

android http post 中文乱码解决

android http post 中文乱码解决

httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

 

archlinux 中文乱码解决

archlinux 中文乱码解决

pacman -S wqy-zenhei ttf-fireflysung(flash乱码)

/etc/locale.gen 设置en_US.UTF8 UTF-8 zh_CN.UTF8 UTF-8

locale-gen

locale

locale -a

/etc/rc.conf 中

LOCALE=en_US.UTF-8

在google浏览器中设置中文字体。

centos 5.3 中文乱码解决

centos 5.3 中文乱码解决

缘由:本人在虚拟机中安装centos 5.3,起初安装时选择了english,后来使用的过程中发现打开网页,会出现中文乱码,无法正常显示。当然,本地文件中的中文更是无法显示。 若是将系统语言language设置成中文,则整个系统全部乱码。

      在网上google来 百度去,reboot了无数遍,硬是都不起作用。只到后来发现这篇文章:http://blog.csdn.net/neverup_/article/details/6443669 才真正解决问题。当然:http://www.xxlinux.com/linux/article/accidence/install/20100330/18150.html 此篇文章对centos乱码问题总结较为全面。

        综上:解决系统中文乱码的步骤为:

1.在光盘中:找到这两个包,安装上就可以支持中文了.
        fonts-chinese-3.02-9.6.el5.noarch.rpm
        fonts-ISO8859-2-75dpi-1.0-17.1.noarch.rpm

         在光盘的CenOs目录下有很多rpm包,找到,拷贝出来,然后通过SSH secure file Transfer 软件 上传到 centos中。再通过rpm -ivh 命令执行。

        或者更简单:通过以下命令也可以安装(需要联网):

 yum -y install fonts-chinese

 yum -y install fonts-ISO8859


安装中文输入法:

命令行输入:

yum install scim

yum install scim-pinyin


2.     编辑这个文件:   vi /etc/sysconfig/i18n   (说明:第二步 是否必须完成 有待考证,但我按第二步做了可以达到目的)

将LANG="en_US.UTF-8"

SYSFONT="latarcyrheb-sun16"

修改原内容为

LANG="zh_CN.GB18030"

LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"

SUPPORTED="zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en"

SYSFONT="lat0-sun16"


3.      最为关键的步骤:命令行输入以下两条语句:   cd /usr/share/fonts/

                                                                                     fc-cache   -fv

           待fc-cache  -fv执行完成后。

4.     注销。logout。然后重新登录,大功告成。

我们今天的关于jdbc-mysql 中文乱码解决jdbc从数据库中读的中文乱码的分享就到这里,谢谢您的阅读,如果想了解更多关于Ajax返回值--中文乱码解决、android http post 中文乱码解决、archlinux 中文乱码解决、centos 5.3 中文乱码解决的相关信息,可以在本站进行搜索。

本文标签: