[CONJ-63] prepareCall() for SELECT statement throws exception Created: 2013-09-12 Updated: 2013-09-13 Resolved: 2013-09-12 |
|
| Status: | Closed |
| Project: | MariaDB Connector/J |
| Component/s: | None |
| Affects Version/s: | 1.1.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Doug Kirk | Assignee: | Vladislav Vaintroub |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | jdbc | ||
| Environment: |
Ubuntu64 connecting to MariaDB 10.0.4 locally |
||
| Description |
|
prepareCall() parses and returns a CallableStatement, a subclass of PreparedStatement in JDBC. In both the Oracle ojdbc6 (connecting to an Oracle DB) and MySQL/J Connector drivers, doing the following works fine (of course the Oracle query selected from different table/schema):
But when it is attempted using the MariaDB client, an exception is incorrectly thrown:
In JDBC, the only real difference is that a CallableStatement allows for OUT parameters. However, without foreknowledge of the SQL being prepared, or code to parse and guess which type of SQL string is being passed to the DB-access code, it is desirable to use CallableStatements in place of PreparedStatements for all queries in systems where stored procedures are used. |
| Comments |
| Comment by Vladislav Vaintroub [ 2013-09-12 ] |
|
This is an interesting interpretation of JDBC, but I have to disagree Here is what official doc says about CallableStatement http://docs.oracle.com/javase/7/docs/api/java/sql/CallableStatement.html The interface used to execute SQL stored procedures. The JDBC API provides a stored procedure SQL escape syntax that allows stored procedures to be called in a standard way for all RDBMSs. This escape syntax has one form that includes a result parameter and one that does not. If used, the result parameter must be registered as an OUT parameter. The other parameters can be used for input, output or both. Parameters are referred to sequentially, by number, with the first parameter being 1. Also, according to the documentation Connection.prepareCall(String sql) creates a CallableStatement object for calling database stored procedures. According to the documentation, conn.prepareCall does not create PreparedStatement for executing a SELECT. You always can use prepareStatement for you purposes. |
| Comment by Vladislav Vaintroub [ 2013-09-12 ] |
|
You also can use prepareStatement , and pass "CALL function(?,?)" to it, this is allowed. you can prepare everything, but CallableStatement ,in this driver, serves the single purpose, that is also documented in the JDBC API, calling stored procedures or functions. |
| Comment by Doug Kirk [ 2013-09-13 ] |
|
You are of course free to disagree but I say you're wrong It is, after all, a subclass of PreparedStatement, which supports all other statement types (aside from functions/procedures with OUT parameters). Why would a subclass add a statement type and not support those of the parent class? It breaks the Liskov substitution principle: From Wikipedia:
|
| Comment by Vladislav Vaintroub [ 2013-09-13 ] |
|
Please feel free to disagree with my disagreement with your statement |