Main Tutorials

java.sql.SQLException: operation not allowed: Ordinal binding and Named binding cannot be combined!

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);

References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments