?
問題起因:
我在使用ant將流程定義和流程相關資源部署到JBPM數據庫中的時候,報了下面一個錯誤。
?
    錯誤提示,大概是:
    
     11:33:40,781 ERROR JDBCExceptionReporter:101 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EQT??u_??????~?<?q_U?<}?~ü?v??ì??‘??R?L\0\0?àvféb|o?r?ê??ù*??ìy?~?Séj÷ §?’L6' at line 1
    
     jbpm org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
    
     ?at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
    
     ?at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    
     ?at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
    
     ?at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)
    
     ?at .................
    
  
    
      很明顯是hibernate執行更新數據庫的時候sql語句出了問題!亂碼!我的jbpm配置與數據庫編碼不一致,導致發sql語句的時候出現亂碼。本來以為很簡單,改一下數據庫編碼就可以了,結果走了很多彎路,先把正確方案總結如下。
    
    
  
看解決方案:
    
     1、關閉MySql服務
    
  
    2、在Mysql的安裝目錄下,在my.ini中添加紅色部分:
    
     [client]
    
     default-character-set=utf8
    
     port=3306
  
[mysql]
    default-character-set=utf8
    
     # 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]
  
    default-character-set=utf8
    
     # The TCP/IP Port the MySQL Server will listen on
    
     port=3306
  
?
    3、重新啟動Mysql服務
    
  
    4、查看編碼方式是否已經修改:
    
  
    打開Mysql控制臺:
    
     mysql> show variables like 'char%';
    
     +--------------------------+---------------------------------------------------------------+
    
     | Variable_name??????????? | Value???????????????????????????????????????????????????????? |
    
     +--------------------------+---------------------------------------------------------------+
    
     | character_set_client???? | utf8????????????????????????????????????????????????????????? |
    
     | character_set_connection | utf8????????????????????????????????????????????????????????? |
    
     | character_set_database?? | gbk?????????????????????????????????????????????????????????? |
    
     | character_set_filesystem | binary??????????????????????????????????????????????????????? |
    
     | character_set_results??? | utf8????????????????????????????????????????????????????????? |
    
     | character_set_server???? | utf8????????????????????????????????????????????????????????? |
    
     | character_set_system???? | utf8????????????????????????????????????????????????????????? |
    
     | character_sets_dir?????? | C:\Program Files (x86)\MySQL\MySQL Server 5.0\share\charsets\ |
    
     +--------------------------+---------------------------------------------------------------+
  
    這樣以后所有新建的數據庫都將采用utf-8編碼。
    
  
    
      
        注:
        
         1、在修改my.ini的過程中,可能會因為操作不當,導致Mysql服務不能啟動,所以操作前先備份。
      
    
    
  
    
      
        2、如果啟動Mysql服務報windows 無法啟動MySQL服務(位于 本地計算機 上)。錯誤10067
      
    
    
  
那么,參照下面解決方案:
    新建my.ini
    
     my.ini內容為:
    
     [client]
    
     default-character-set=utf8
    
     port=3306
  
    [mysql]
    
     default-character-set=utf8
  
    [mysqld]
    
     port=3306
  
    #Path to installation directory. All paths are usually resolved relative to this.
    
     basedir="C:/Program Files (x86)/MySQL/MySQL Server 5.0/"
  
    #Path to the database root
    
     datadir="C:/Program Files (x86)/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
  
    # The default storage engine that will be used when create new tables when
    
     default-storage-engine=INNODB
  
    # Set the SQL mode to strict
    
     sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    
     max_connections=100
    
     query_cache_size=0
    
     table_cache=256
    
     tmp_table_size=5M
    
     thread_cache_size=8
    
     myisam_max_sort_file_size=100G
    
     myisam_max_extra_sort_file_size=100G
    
     myisam_sort_buffer_size=8M
    
     key_buffer_size=8M
    
     read_buffer_size=64K
    
     read_rnd_buffer_size=256K
    
     sort_buffer_size=212K
    
     innodb_data_home_dir="C:/MySQL Datafiles/"
    
     innodb_additional_mem_pool_size=2M
    
     innodb_flush_log_at_trx_commit=1
    
     innodb_log_buffer_size=1M
    
     innodb_buffer_pool_size=8M
    
     innodb_log_file_size=10M
    
     innodb_thread_concurrency=8
  
?
    #注:
    
     #注意紅色部分要根據你自己的安裝目錄進行設定。
  
    
     將該文件復制到mysql安裝目錄中和系統的windows目錄中。如果原來存在,替換掉原來的。啟動MySql服務即可!
  
?
    
      
        忽然想到自己的Linux服務器上的MySql也不完全是utf8編碼的,那怎么改呢?大致思路和在windows下是一樣的。
        
      
    
  
    1、中止MySQL服務(bin/mysqladmin -u root shutdown) 
    
  
    2、在/etc/下找到my.cnf,如果沒有,就把MySQL的安裝目錄下的support-files目錄下的
    
     my-medium.cnf復制到/etc/下并改名為my.cnf即可 
    
  
    3、打開my.cnf以后,在[client]和[mysqld]下面均加上default-character-set=utf8,
    
     保存并關閉 
    
  
    4、啟動MySQL服務(bin/mysqld_safe &)?
    
     ?
    
  
總結:
    
      這樣的修改一勞永逸,非常簡單,今后MySQL一切相關的默認編碼均為UTF-8了,創建新表的時候無需再次設置。如果MySql還沒有安裝,那么建議在安裝Mysql的時候,就將默認編碼設置為utf8,我們的項目中也應該將編碼設置為utf8,這樣后續會規避很多問題。需要注意的是,當前數據庫中已經存在的數據仍保留現有的編碼方式,因此需要自行轉碼,
      
    
  
方法在網上有很多,不再贅述。
?
?
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
					微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
					
