现在做的一个小项目中用MySql数据库,使用latin1编码,这个已经不能改了
请问在进行查询与插入的时候应该进行怎样的相关转换才能使程序不会出现乱码,同时保证数据库中数据的完整性?再有,在JDBC连接URL中,useUnicode、characterEncoding两个参数分别是什么意思?在线等,谢谢!

解决方案 »

  1.   

    “使用latin1编码,这个已经不能改了”这个什么意思?
      什么叫不能改洛。
      在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
      

  2.   

    装个mysql的图形界面管理工具,很容易改编码的。
    下载地址: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 ]
      

  3.   

    数据库连接时设置编码
    jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gb2312
    或jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8 
      

  4.   


    jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=gb2312 
    或jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8 
      

  5.   

    用MySql数据库,使用latin1编码—————————————————你确定是 latin1 的编码?在这个编码下不能插入汉字数据的吧?
      

  6.   

    下面这些摘自 MySQL JDBC(Connector/J) 的文档说明。useUnicode
        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')
      

  7.   

    jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8如此设置URL的话,查询后获得的数据仍然需要重新使用UTF-8转码吧(latin1->UFT-8)
    同时,插入之前也必须将中文字符转码为latin1(UFT-8->latin1)?
      

  8.   

    建议楼主使用gbk进行数据库编码,utf-8或者gb2312进行页面编码,就不会出现乱码了,latin1就是强制转化也不行
      

  9.   

    jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=gb2312 
    或jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8 
      

  10.   


    jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gb2312 
    或jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8 
      

  11.   

    jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=gb2312 
    或jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8