0

I use com.sybase.jdbc42.jdbc.SybDriver to connect to sybase. I get

SQL Anywhere Error -188: Not enough values for host variables

when I execute multiple statements like this :

delete from CHARGING_PLAN2APPLICATIONS where CHARGING_P LAN_ID=?;update CHARGING_PLAN set NAME= ? ,ADMIN =?,LAST_CHANGE= current utc timestamp where ID=?;

It could happen with different statements: delete + update or insert + insert. With remote debug I checked that I pass all variabless required for statement. In pseudocode it looks like that:

public void executeMultipleStatementQuery(List<TransactionData> queries) throws SQLException {
    Connection conn = getConnection();
    StringBuilder fullStatement = new StringBuilder(500);
    List<Object> totalParams = new ArrayList<>();
    // save all queries to one string and separate them with ";"
    for (TransactionData query : queries) {
        fullStatement.append(query.getSqlStatement());
        fullStatement.append(";");
        Collections.addAll(totalParams, query.getParams());
    }
    PreparedStatement stm = conn.prepareStatement(fullStatement.substring(0, fullStatement.length() - 1));
    // save all parameters to PreparedStatement
    for (Object param : totalParams) {
        if (param instanceof NullValue) {
            stm.setNull(i, ((NullValue) param).getType());
        } else {
            stm.setObject(i, param);
        }
        i++;
    }
}

But get SQL error.

When I sent each statement separately - it works...

What could be a root cause of such error?

Igor_M
  • 308
  • 2
  • 12
  • try pushing PreparedStatement stm = conn.prepareStatement(...) inside the cycle and explicitly close it after each iteration – access_granted Mar 29 '23 at 18:22
  • @access_granted, this is almost what I do: I refactored this method and call it with 1 query, not with the list. But my purpose was to push multiple queries in 1 connection. – Igor_M Mar 31 '23 at 04:38

0 Answers0