您的位置:首页 > 产品设计 > 产品经理

jbpm Could not execute JDBC batch update jbpm部署流程定义到MySql报乱码解决方案

2016-06-23 22:12 681 查看
 jbpm Could not execute JDBC batch update

编码没有统一   utf8的确会报一些莫名的错

还好jbpm的解决方案挺多的


 

 

问题起因:

我在使用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,这样后续会规避很多问题。需要注意的是,当前数据库中已经存在的数据仍保留现有的编码方式,因此需要自行转码,

方法在网上有很多,不再赘述。

 

 来自:http://blog.csdn.net/shan9liang/article/details/9136875
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: