java jdbc sql 参数,Java JDBC预准备语句的最大参数标记

Im building a large database call using PreparedStatement that has 2000+ parameter markers.

Im getting this error

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.(JtdsPreparedStatement.java:107)

Caused by: java.sql.SQLException: Prepared or callable statement has more than 2000 parameter markers.

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?

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值