|
From: <jue...@we...> - 2004-03-16 14:37:53
|
Will, everyone,
Our current JdbcTemplate does indeed not cover such use cases: It rather =
assumes that each operation will use its own (Prepared)Statement =
instance.=20
Therefore, I've added further JdbcTemplate methods that take generic =
callback actions:
- execute(StatementCallback)
- execute(String sql, PreparedStatementCallback)
- execute(String sql, CallableStatementCallback)
Each of the callback interfaces has a single "Object =
doInStatement(Statement)"-style method, allowing for any number of =
operations to be performed on the passed-in statement.
There also overloaded versions that take statement creators:
- execute(PreparedStatementCreator, PreparedStatementCallback)
- execute(CallableStatementCreator, CallableStatementCallback)
I've refactored all of JdbcTemplate's existing data access methods to =
use those generic execute methods with inner-class callback =
implementations: This has removed almost all internal code duplications =
that were necessary before.
I believe that this is an important addition: Reusing a statement =
instance for multiple executions with different parameters is a valid =
and quite common use case. And cleaning the JdbcTemplate internals is a =
nice side effect.
Awaiting your feedback! (I haven't committed that change yet, but intend =
to do so before the release this weekend.)
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf Of
Will Jaynes
Sent: Monday, March 15, 2004 8:10 PM
To: spr...@li...
Subject: [Springframework-user] JdbcTemplate update example
I'm converting some of my JDBC DAOs to Spring JdbcTempate usage. I'm=20
afraid I need an example of reusing a PreparedStatement over a number of =
updates. The update methods for JdbcTemplate all seem to create a=20
PreparedStatement, so perhaps I can't use any of them.
The old code looks something like:
public void doAnUpdate(Connection conn, String[] ids) {
...
ps =3D conn.prepareStatement("Update A set B =3D null where id =3D ?");
for (int i=3D0; i<ids.length; i++)
ps.setString(id[i]);
ps.executeUpdate();
}
...
Thanks for any help,
Will
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli=
ck
_______________________________________________
Springframework-user mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-user
|