DBUnit向mysql導資料異常

來源:互聯網
上載者:User
C:\Users\Administrator\Desktop\defaultDB - mysql專用\build.xml:50: org.dbunit.DatabaseUnitException: java.sql.SQLException: Incorrect string value: '\xE3\x80\x8A\xE8\xAE\xBE...' for column 'DOCCONTENT' at row 1at org.dbunit.ant.Operation.execute(Operation.java:175)at org.dbunit.ant.DbUnitTask.execute(DbUnitTask.java:272)at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)at org.apache.tools.ant.Task.perform(Task.java:348)at org.apache.tools.ant.Target.execute(Target.java:392)at org.apache.tools.ant.Target.performTasks(Target.java:413)at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)at org.apache.tools.ant.Project.executeTargets(Project.java:1251)at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442)at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)at org.apache.tools.ant.Task.perform(Task.java:348)at org.apache.tools.ant.Target.execute(Target.java:392)at org.apache.tools.ant.Target.performTasks(Target.java:413)at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)at org.apache.tools.ant.Project.executeTarget(Project.java:1368)at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)at org.apache.tools.ant.Project.executeTargets(Project.java:1251)at org.apache.tools.ant.Main.runBuild(Main.java:811)at org.apache.tools.ant.Main.startAnt(Main.java:217)at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)java.sql.SQLException: Incorrect string value: '\xE3\x80\x8A\xE8\xAE\xBE...' for column 'DOCCONTENT' at row 1at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1124)at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:676)at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:773)at org.dbunit.database.statement.SimplePreparedStatement.addBatch(SimplePreparedStatement.java:67)at org.dbunit.database.statement.AutomaticPreparedBatchStatement.addBatch(AutomaticPreparedBatchStatement.java:57)at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:178)at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:67)at org.dbunit.ant.Operation.execute(Operation.java:171)at org.dbunit.ant.DbUnitTask.execute(DbUnitTask.java:272)at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)at org.apache.tools.ant.Task.perform(Task.java:348)at org.apache.tools.ant.Target.execute(Target.java:392)at org.apache.tools.ant.Target.performTasks(Target.java:413)at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)at org.apache.tools.ant.Project.executeTargets(Project.java:1251)at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442)at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)at org.apache.tools.ant.Task.perform(Task.java:348)at org.apache.tools.ant.Target.execute(Target.java:392)at org.apache.tools.ant.Target.performTasks(Target.java:413)at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)at org.apache.tools.ant.Project.executeTarget(Project.java:1368)at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)at org.apache.tools.ant.Project.executeTargets(Project.java:1251)at org.apache.tools.ant.Main.runBuild(Main.java:811)at org.apache.tools.ant.Main.startAnt(Main.java:217)at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)Total time: 25 seconds

開始以為是編碼問題,後來經過查詢,探索服務器端編碼和用戶端編碼都是UTF-8編碼,所以編碼沒問題;

通過 show character set;命令發現Utf8編碼的最大編碼長度為3,這個似乎不會影響都資料的儲存,但是懷疑是不是欄位的長度限制的問題,把DocContent這個欄位類型從Text設定LongText,問題解決。

Text、MediumText和LongText支援的長度如下(來自MySql 5.1手冊):

 

TINYTEXT

最大長度為255(28–1)字元的TEXT列。

TEXT[(M)]

最大長度為65,535(216–1)字元的TEXT列。

可以給出可選長度M。則MySQL將列建立為最小的但足以容納M字元長的值的TEXT類型。

MEDIUMTEXT

最大長度為16,777,215(224–1)字元的TEXT列。

LONGTEXT

最大長度為4,294,967,295或4GB(232–1)字元的TEXT列。LONGTEXT列的最大有效(允許的)長度取決於用戶端/伺服器協議中配置最大包大小和可用的記憶體。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.