现在做的一个小项目中用MySql数据库,使用latin1编码,这个已经不能改了
请问在进行查询与插入的时候应该进行怎样的相关转换才能使程序不会出现乱码,同时保证数据库中数据的完整性?再有,在JDBC连接URL中,useUnicode、characterEncoding两个参数分别是什么意思?在线等,谢谢!
请问在进行查询与插入的时候应该进行怎样的相关转换才能使程序不会出现乱码,同时保证数据库中数据的完整性?再有,在JDBC连接URL中,useUnicode、characterEncoding两个参数分别是什么意思?在线等,谢谢!
什么叫不能改洛。
在mysql的配置文件中就能改。
在my.ini里面可以修改
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]port=3306[mysql]default-character-set=GBK
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]# The TCP/IP Port the MySQL Server will listen on
port=3306
#Path to installation directory. All paths are usually resolved relative to this.
basedir="C:/Program Files/MySQL/MySQL Server 5.0/"#Path to the database root
datadir="C:/Program Files/MySQL/MySQL Server 5.0/Data/"# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=UTF8
下载地址:http://mysql.ntu.edu.tw/Downloads/MySQLGUITools/mysql-gui-tools-5.0-r12-win32.msi
useUnicode=true
characterEncoding=utf-8(建议统一编码用utf-8)[例子:jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8 ]
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gb2312
或jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=gb2312
或jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8
Should the driver use Unicode character encodings when handling strings?
Should only be used when the driver can't determine the character set mapping,
or you are trying to 'force' the driver to use a character set that MySQL either
doesn't natively support (such as UTF-8), true/false, defaults to 'true'.characterEncoding
If 'useUnicode' is set to true, what character encoding should the driver
use when dealing with strings? (defaults is to 'autodetect')
同时,插入之前也必须将中文字符转码为latin1(UFT-8->latin1)?
或jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gb2312
或jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
或jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8