【原创】DB2数据库乱码造成启动Tomcat5.5加载数据抛出异常!-已经解决

从DB2服务器导出文本数据导入本机,启动Tomcat5.5报错大概日志如下org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select this_.ID as ID9_0_, this_.PARENTID as PARENTID9_0_, this_.CODE as CODE9_0_, this_.REMARK as REMARK9_0_, this_.CODE_DICT as CODE5_9_0_, this_.SORTINDEX as SORTINDEX9_0_, this_.NAME as NAME9_0_, this_.ADDITIONAL_CTRL as ADDITIONAL8_9_0_, this_.VALID_FLAG as VALID9_9_0_, this_.DISPLAY_FLAG as DISPLAY10_9_0_ from SYS_DICTIONARY this_ order by this_.SORTINDEX asc]; SQL state [null]; error code [-99999]; null; nested exception is com.ibm.db2.jcc.c.SqlException
Caused by:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bdcAccnReportQueryService' defined in URL [file:/E:/software/Tomcat5.5/webapps/cim/WEB-INF/classes/module/base/spring-service-info.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'noTranBatcher' defined in URL [file:/E:/software/Tomcat5.5/webapps/cim/WEB-INF/classes/module/base/spring-service-info.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysDictionaryService' defined in URL [file:/E:/software/Tomcat5.5/webapps/cim/WEB-INF/classes/module/base/spring-service-info.xml]: Invocation of init method failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select this_.ID as ID9_0_, this_.PARENTID as PARENTID9_0_, this_.CODE as CODE9_0_, this_.REMARK as REMARK9_0_, this_.CODE_DICT as CODE5_9_0_, this_.SORTINDEX as SORTINDEX9_0_, this_.NAME as NAME9_0_, this_.ADDITIONAL_CTRL as ADDITIONAL8_9_0_, this_.VALID_FLAG as VALID9_9_0_, this_.DISPLAY_FLAG as DISPLAY10_9_0_ from SYS_DICTIONARY this_ order by this_.SORTINDEX asc]; SQL state [null]; error code [-99999]; null; nested exception is com.ibm.db2.jcc.c.SqlException
Caused by:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'noTranBatcher' defined in URL [file:/E:/software/Tomcat5.5/webapps/cim/WEB-INF/classes/module/base/spring-service-info.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysDictionaryService' defined in URL [file:/E:/software/Tomcat5.5/webapps/cim/WEB-INF/classes/module/base/spring-service-info.xml]: Invocation of init method failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select this_.ID as ID9_0_, this_.PARENTID as PARENTID9_0_, this_.CODE as CODE9_0_, this_.REMARK as REMARK9_0_, this_.CODE_DICT as CODE5_9_0_, this_.SORTINDEX as SORTINDEX9_0_, this_.NAME as NAME9_0_, this_.ADDITIONAL_CTRL as ADDITIONAL8_9_0_, this_.VALID_FLAG as VALID9_9_0_, this_.DISPLAY_FLAG as DISPLAY10_9_0_ from SYS_DICTIONARY this_ order by this_.SORTINDEX asc]; SQL state [null]; error code [-99999]; null; nested exception is com.ibm.db2.jcc.c.SqlException
Caused by:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysDictionaryService' defined in URL [file:/E:/software/Tomcat5.5/webapps/cim/WEB-INF/classes/module/base/spring-service-info.xml]: Invocation of init method failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select this_.ID as ID9_0_, this_.PARENTID as PARENTID9_0_, this_.CODE as CODE9_0_, this_.REMARK as REMARK9_0_, this_.CODE_DICT as CODE5_9_0_, this_.SORTINDEX as SORTINDEX9_0_, this_.NAME as NAME9_0_, this_.ADDITIONAL_CTRL as ADDITIONAL8_9_0_, this_.VALID_FLAG as VALID9_9_0_, this_.DISPLAY_FLAG as DISPLAY10_9_0_ from SYS_DICTIONARY this_ order by this_.SORTINDEX asc]; SQL state [null]; error code [-99999]; null; nested exception is com.ibm.db2.jcc.c.SqlException
Caused by:
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select this_.ID as ID9_0_, this_.PARENTID as PARENTID9_0_, this_.CODE as CODE9_0_, this_.REMARK as REMARK9_0_, this_.CODE_DICT as CODE5_9_0_, this_.SORTINDEX as SORTINDEX9_0_, this_.NAME as NAME9_0_, this_.ADDITIONAL_CTRL as ADDITIONAL8_9_0_, this_.VALID_FLAG as VALID9_9_0_, this_.DISPLAY_FLAG as DISPLAY10_9_0_ from SYS_DICTIONARY this_ order by this_.SORTINDEX asc]; SQL state [null]; error code [-99999]; null; nested exception is com.ibm.db2.jcc.c.SqlException
Caused by:
com.ibm.db2.jcc.c.SqlException
at com.ibm.db2.jcc.c.s.a(s.java:1517)
at com.ibm.db2.jcc.c.s.m(s.java:465)
at com.ibm.db2.jcc.c.s.M(s.java:1102)
at com.ibm.db2.jcc.c.lf.getString(lf.java:959)
at com.ibm.db2.jcc.c.lf.getString(lf.java:1290)
at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:224)
at org.hibernate.type.StringType.get(StringType.java:18)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2031)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1371)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1299)
at org.hibernate.loader.Loader.getRow(Loader.java:1197)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)

======================================================================

【解决方法】:经过48小时的折腾结果发现,从服务器导出的文本数据是GBK编码,而DB2数据库在建数据库的时候选择的是UTF-8编码,所以导入本地数据库后中文是乱码和null,只要把服务器导出来的文本数据使用记事本或其它的编辑器(如:EditPlus,UltraEdit等)把文本文件保存为UTF-8格工,重新再导入数据库即可!

你可能感兴趣的:(java,spring,Hibernate,bean,db2)