Java JDBC预准备语句的最大参数标记 [英] Java JDBC prepared statement maximum parameter markers
问题描述
我使用 PreparedStatement
构建一个大型数据库调用,它有2000多个参数标记。
Im building a large database call using PreparedStatement
that has 2000+ parameter markers.
我收到此错误
Caused by: java.sql.SQLException: Prepared or callable statement has more than 2000 parameter markers.
at net.sourceforge.jtds.jdbc.SQLParser.parse(SQLParser.java:1139)
at net.sourceforge.jtds.jdbc.SQLParser.parse(SQLParser.java:156)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.<init>(JtdsPreparedStatement.java:107)
Caused by: java.sql.SQLException: Prepared or callable statement has more than 2000 parameter markers.
我尝试搜索API文档和谷歌但无法找到如何配置它。
I tried searching the API Docs and google but couldnt find how to configure this.
有谁知道是否有可能达到这个限制?我知道这将是一个缓慢的数据库调用,但现在这很好。
Does anyone know if it is possible to up this limit? I am aware it is going to be a slow database call but that is fine for now.
从长远来看,这也会给我带来任何问题,我最好分批运行吗?
Also will this cause me any issues in the long run, would I be better off running it in batches?
推荐答案
像你这样的接缝卡在2000.这是驱动源的一个切口。
Seams like you're stuck at 2000. Here is a cut out from the driver source.
if (params != null && params.size() > 255
&& connection.getPrepareSql() != TdsCore.UNPREPARED
&& procName != null) {
int limit = 255; // SQL 6.5 and Sybase < 12.50
if (connection.getServerType() == Driver.SYBASE) {
if (connection.getDatabaseMajorVersion() > 12 ||
connection.getDatabaseMajorVersion() == 12 &&
connection.getDatabaseMinorVersion() >= 50) {
limit = 2000; // Actually 2048 but allow some head room
}
} else {
if (connection.getDatabaseMajorVersion() == 7) {
limit = 1000; // Actually 1024
} else if (connection.getDatabaseMajorVersion() > 7) {
limit = 2000; // Actually 2100
}
}
if (params.size() > limit) {
throw new SQLException(
Messages.get("error.parsesql.toomanyparams",
Integer.toString(limit)),
"22025");
}
}
此处是一个博客,其中包含有关如何解决此问题的示例。
Here are a blog with examples on how to solve it.
这篇关于Java JDBC预准备语句的最大参数标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!