首页 > 解决方案 > DataIntegrityViolationException:关于 PreparedStatementCallback 的数据截断

问题描述

我有一个关于 PreparedStatementCallback 的问题,如下所示:

 Error! Conflict [#409]: PreparedStatementCallback; SQL [EXEC de_table ?, ?, ?, ?, ?, ?, ?, ?]; Data truncation; nested exception is java.sql.DataTruncation: Data truncation

语境:

我有一个部分用于从我的应用程序中生成包含值的表,直到最近我发现除了我正在测试的 4 个数据库之一之外没有问题。问题是我不明白为什么会出现这种情况,因为我已经在其他几个数据库上对其进行了测试,并且此页面按预期工作。因此我假设代码是好的,但数据不是。我已经执行了相同的过程来填充表格,但是错误仍然存​​在。

我的请求 URL 包含以下内容:

accessInd: Any
client: %
endDate: 2020-02-15 23:59:59
entDate: 2020-01-30 11:32:49
entitlementSetMode: 1
entitlementType: Historical
groupItem: %
groupType: 15
service: %
site: %
siteName: %
startDate: 2020-01-30 00:00:00
subservice: %
type: %
userLogin: %

需要传递到准备好的语句中的任何值如下:

                        exampleTable.getSite(),
                        exampleTable.getGroupType(),
                        exampleTable.getGroupItem(),
                        exampleTable.getService(),
                        exampleTable.getType(),
                        exampleTable.getSubservice(),
                        exampleTable.getEndDate(),
                        exampleTable.getMaxRowCount()

有谁知道为什么这不起作用或有任何帮助?此外,如果有人想知道,% 仅用于请求与该值相关的所有内容。谢谢。

标签: javasqldatabase

解决方案


检查您的数据库的字段类型/大小是否支持您尝试放入其中的数据长度。

可能工作的三个数据库和不工作的数据库之间存在细微的架构差异。

假设yourdb.exampleTable.sitefield 是 aVARCHAR(10)并且exampleTable.getSite()is "my-site-name-is-more-than-10-chars-long",这将导致java.sql.DataTruncation抛出此异常。


推荐阅读