java - 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()
有谁知道为什么这不起作用或有任何帮助?此外,如果有人想知道,% 仅用于请求与该值相关的所有内容。谢谢。
解决方案
检查您的数据库的字段类型/大小是否支持您尝试放入其中的数据长度。
可能工作的三个数据库和不工作的数据库之间存在细微的架构差异。
假设yourdb.exampleTable.site
field 是 aVARCHAR(10)
并且exampleTable.getSite()
is "my-site-name-is-more-than-10-chars-long"
,这将导致java.sql.DataTruncation
抛出此异常。
推荐阅读
- javascript - 避免来自 javascript 中未定义输入字段的错误
- mysql - knex mysql 为同一服务器上 3 个应用程序中的 1 个连接 ECONNREFUSED
- c - 将位于堆中的数组传递给 C 中的 Func
- assembly - 我正在寻找如何将 3 个数字与 2 位数字相加
- c# - AutoFixture.Freeze IEnumarable 的 Mocks
- amazon-cloudwatchlogs - AWS Cloudwatch:如何将实例名称/自定义字段添加到日志中?
- javascript - React Props 不更新状态
- php - 使用 nginx 在 Laravel API 路由上找不到 404
- eclipse - 在 Eclipse 安装期间验证 JCE 证书
- regex - 正则表达式 - 仅将输入和输出替换为小数?