[jira] Created: (DBUTILS-50) Support CallableStatement "out" parameters

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (DBUTILS-50) Support CallableStatement "out" parameters

JIRA jira@apache.org
Support CallableStatement "out" parameters
------------------------------------------

                 Key: DBUTILS-50
                 URL: https://issues.apache.org/jira/browse/DBUTILS-50
             Project: Commons DbUtils
          Issue Type: New Feature
            Reporter: Dan Fabulich


Using fillStatement and the new fillStatementWithBean, you can use a CallableStatement like a PreparedStatement, retrieve its ResultSet and handle it with a ResultSetHandler.  But we don't yet support registering "out" parameters on the CallableStatement in a convenient way and retrieving them back into an object.

DBUTILS-28 requests stored procedure support and provides a patch, but I don't like the patch.  Regardless, we really should support a few helpers like:

{code}
void registerOutParameters(CallableStatement stmt, int... sqlTypes)

Object[] getOutParameters(CallableStatement stmt)

void registerOutParameters(CallableStatement stmt, Class<?> beanClass)

<T> T getOutParameters(CallableStatement stmt, Class<T> beanClass)
{code}

You should be able to write code like this:

{code}
CallableStatement stmt = runner.prepareCall(myString);
helper.registerOutParameters(stmt, MyBean.class);
queryRunner.fillStatement(stmt, foo, bar, baz);
stmt.executeUpdate();
MyBean bean = helper.getOutParameters(stmt, MyBean.class);
{code}

Or like this:

{code}
CallableStatement stmt = runner.prepareCall(myString);
helper.registerOutParameters(stmt, TINYINT, DECIMAL);
queryRunner.fillStatement(stmt, foo, bar, baz);
stmt.executeUpdate();
Object[] result = helper.getOutParameters(stmt);
{code}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (DBUTILS-50) Support CallableStatement "out" parameters

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/DBUTILS-50?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12677040#action_12677040 ]

Liam Seamus Coughlin commented on DBUTILS-50:
---------------------------------------------

I really dislike the idea of having a public fillStatementMethod, or of having a user deal with a statement directly at all really -- part of debutils is hiding a lot of the nastyness associated with jdbc -- I'd rather see a CallableStatementRunner which has a seperate interface from the queryrunner then a mixnmatch of helper object calls and jdbc calls, and direct calls to row handlers, etc.

> Support CallableStatement "out" parameters
> ------------------------------------------
>
>                 Key: DBUTILS-50
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-50
>             Project: Commons DbUtils
>          Issue Type: New Feature
>            Reporter: Dan Fabulich
>
> Using fillStatement and the new fillStatementWithBean, you can use a CallableStatement like a PreparedStatement, retrieve its ResultSet and handle it with a ResultSetHandler.  But we don't yet support registering "out" parameters on the CallableStatement in a convenient way and retrieving them back into an object.
> DBUTILS-28 requests stored procedure support and provides a patch, but I don't like the patch.  Regardless, we really should support a few helpers like:
> {code}
> void registerOutParameters(CallableStatement stmt, int... sqlTypes)
> Object[] getOutParameters(CallableStatement stmt)
> void registerOutParameters(CallableStatement stmt, Class<?> beanClass)
> <T> T getOutParameters(CallableStatement stmt, Class<T> beanClass)
> {code}
> You should be able to write code like this:
> {code}
> CallableStatement stmt = runner.prepareCall(myString);
> helper.registerOutParameters(stmt, MyBean.class);
> queryRunner.fillStatement(stmt, foo, bar, baz);
> stmt.executeUpdate();
> MyBean bean = helper.getOutParameters(stmt, MyBean.class);
> {code}
> Or like this:
> {code}
> CallableStatement stmt = runner.prepareCall(myString);
> helper.registerOutParameters(stmt, TINYINT, DECIMAL);
> queryRunner.fillStatement(stmt, foo, bar, baz);
> stmt.executeUpdate();
> Object[] result = helper.getOutParameters(stmt);
> {code}

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.