SQLException: Cannot send expression in current context

I ran into this exception when calling a stored procedure through a prepared statement, however it works for the called statement. I am wondering if I need to use a callable operator to call a stored procedure in voltdb?

String sql = "{call get_city_by_country(?)}";
PreparedStatement stat = conn.prepareStatement(sql);
stat.setString(1, "china");
ResultSet results = stat.executeQuery();


Throws the following exception:

Exception in thread "main" java.sql.SQLException: Cannot submit statement in current context: '{call get_city_by_country(?)};'.
at org.voltdb.jdbc.SQLError.get(SQLError.java:45)
at org.voltdb.jdbc.JDBC4PreparedStatement.executeQuery(JDBC4PreparedStatement.java:121)


It works well.

CallableStatement proc = conn.prepareCall(sql);
proc.setString(1, "china");
ResultSet results = proc.executeQuery();



source to share

1 answer

It looks like your driver only supports CALL

escape on CallableStatement

. Therefore, you need to use CallableStatement


Section 6.4 Java EE JDBC Compliance with JDBC 4.2 specification, however, says (empasis mine):

Drivers must support stored procedures. The method DatabaseMetaData


must return true

. The driver must also support the full JDBC API syntax to call stored procedures with the following methods in the classes Statement

, PreparedStatement



  • executeUpdate

  • executeQuery

  • execute

This means that your driver is not fully Java EE JDBC Compliance compliant. You might want to consider filing a bug report with your driver vendor.



All Articles