ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Ellis <ellis....@gmail.com>
Subject Re: Custom ResultSet handler
Date Tue, 02 Feb 2010 11:48:10 GMT
On 2 February 2010 11:43, Martin Ellis <ellis.m.a@gmail.com> wrote:
> On 2 February 2010 09:20, Stephen Friedrich
> <stephen.friedrich@fortis-it.eu> wrote:
>> Another option for me would be to somehow get the final SQL statement and
>> parameters, then execute that statement myself. Is that possible somehow?
>
> I have something like this:
>
>        String sqlId = ... // The 'id' of the SQL statement in the XML config
>        Object param = ... // The parameter object for the query
>        ResultSet rs = null;
>        PreparedStatement ps = null;
>        try {
>            Configuration conf = sf.getConfiguration();
>            MappedStatement ms = conf.getMappedStatement(sqlId);
>            BoundSql boundSql = ms.getBoundSql(param);
>            ParameterHandler pHandler = new
> DefaultParameterHandler(ms, param, boundSql);
>
>            stmt = conn.prepareStatement(boundSql.getSql());
>            pHandler.setParameters(stmt);
>            rs = stmt.executeQuery();

In the above, conn is initialised as follows:

   Environment env = sf.getConfiguration().getEnvironment();
   conn = sf.getConfiguration().getEnvironment().getDataSource().getConnection();
   Transaction txn = env.getTransactionFactory().newTransaction(conn, false);

Probably want to commit/rollback your txn afterwards.

Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Mime
View raw message