Java JDBC prepared statement maximum parameter markers

前端 未结 1 1237
南方客
南方客 2021-02-04 07:26

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

Im getting this error

Caused by: java.sql.SQLExc         


        
1条回答
  •  无人及你
    2021-02-04 07:47

    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)
提交回复
热议问题