java.sql.SQLException: operation not allowed: Ordinal binding and Named binding cannot be combined!
By:Roy.LiuLast updated:2019-08-11
Ordinal binding or index binding:
String name = stat.getString(2); BigDecimal salary = stat.getBigDecimal(3); Timestamp createdDate = stat.getTimestamp(4);
Named binding:
String name = stat.getString("NAME"); BigDecimal salary = stat.getBigDecimal("SALARY"); Timestamp createdDate = stat.getTimestamp("CREATED_DATE");
If we mixed both like this:
String name = stat.getString(2); BigDecimal salary = stat.getBigDecimal("SALARY"); Timestamp createdDate = stat.getTimestamp(4);
Error:
java.sql.SQLException: operation not allowed: Ordinal binding and Named binding cannot be combined!
JDBC CallableStatement
A CallableStatement example to call an IN and OUT store procedure:
// IN with ordinal binding callableStatement.setInt(1, 999); // OUT with name binding String name = callableStatement.getString("NAME"); BigDecimal salary = callableStatement.getBigDecimal("SALARY"); Timestamp createdDate = callableStatement.getTimestamp("CREATED_DATE");
Output
java.sql.SQLException: operation not allowed: Ordinal binding and Named binding cannot be combined!
To fix it, update all to ordinal binding or name binding:
callableStatement.setInt(1, 999); String name = callableStatement.getString(2); BigDecimal salary = callableStatement.getBigDecimal(3); Timestamp createdDate = callableStatement.getTimestamp(4);
From:一号门
Previous:Java Prime Numbers examples
COMMENTS