I encountered this exception when calling a stored procedure through a prepared statement, however, it works for callable statement. I am wondering if it is a must to use callable statement for invoking 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 exception below:
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)
This one works fine.
CallableStatement proc = conn.prepareCall(sql);
proc.setString(1, "china");
ResultSet results = proc.executeQuery();
It look like your driver only supports the CALL
escape on CallableStatement
. So you need to use CallableStatement
instead.
Section 6.4 Java EE JDBC Compliance of the JDBC 4.2 specification however says (empasis mine):
Drivers must support stored procedures. The
DatabaseMetaData
methodsupportsStoredProcedures
must returntrue
. The driver must also support the full JDBC API escape syntax for calling stored procedures with the following methods on theStatement
,PreparedStatement
, andCallableStatement
classes:
executeUpdate
executeQuery
execute
This means that your driver is not fully compliant with the Java EE JDBC Compliance requirements. You might want to consider filing a bug report with the driver vendor.