You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by george stewart <gs...@us-south.net> on 2003/02/28 16:17:52 UTC

[dbutils]update with results

Hey guys,

Wouldn't it be helpful to add an update which returns results?

Something like:

    public static int executeUpdate(Connection connection, String query, 
                                        Object[] vals,
                                        ResultSetHandler rsh
                                       ) throws SQLException 
    {
        PreparedStatement stmt = null;

        stmt = connection.prepareStatement(query);
        fillStatement(stmt, vals);
        try {
            if (stmt.executeUpdate())
            {
                stmt.getMoreResults();
                return rsh.handle(stmt.getResultSet());
            }
            return false;
       } catch(SQLException sqle) {
            String msg = sqle.getMessage() + " in query " + query + 
                java.util.Arrays.asList(vals).toString();
            SQLException newsqle = new SQLException(msg);
            newsqle.setNextException(sqle);
            throw newsqle;
        } finally {
            closeQuietly(stmt);
        }
    }


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [dbutils]update with results

Posted by Juozas Baliuka <ba...@mwm.lt>.
Do some drivers return not null resultset after "executeUpdate" ?


> Hey guys,
> 
> Wouldn't it be helpful to add an update which returns results?
> 
> Something like:
> 
>     public static int executeUpdate(Connection connection, String query, 
>                                         Object[] vals,
>                                         ResultSetHandler rsh
>                                        ) throws SQLException 
>     {
>         PreparedStatement stmt = null;
> 
>         stmt = connection.prepareStatement(query);
>         fillStatement(stmt, vals);
>         try {
>             if (stmt.executeUpdate())
>             {
>                 stmt.getMoreResults();
>                 return rsh.handle(stmt.getResultSet());
>             }
>             return false;
>        } catch(SQLException sqle) {
>             String msg = sqle.getMessage() + " in query " + query + 
>                 java.util.Arrays.asList(vals).toString();
>             SQLException newsqle = new SQLException(msg);
>             newsqle.setNextException(sqle);
>             throw newsqle;
>         } finally {
>             closeQuietly(stmt);
>         }
>     }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org