|
From: Jonathan H. <jh...@ad...> - 2004-03-17 03:49:53
|
Nice :)
----- Original Message -----=20
From: "j=FCrgen h=F6ller [werk3AT]" <jue...@we...>
To: <spr...@li...>;
<spr...@li...>
Sent: Tuesday, March 16, 2004 7:39 AM
Subject: [Springframework-developer] Re: [Springframework-user] JdbcTempl=
ate
update example
> Will, everyone,
>
> Our current JdbcTemplate does indeed not cover such use cases: It rathe=
r
assumes that each operation will use its own (Prepared)Statement instance.
>
> 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 u=
se
those generic execute methods with inner-class callback implementations:
This has removed almost all internal code duplications that were necessar=
y
before.
>
> I believe that this is an important addition: Reusing a statement insta=
nce
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 inten=
d
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
> afraid I need an example of reusing a PreparedStatement over a number o=
f
> updates. The update methods for JdbcTemplate all seem to create a
> 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=3Dc=
lick
> _______________________________________________
> Springframework-user mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-user
>
>
> -------------------------------------------------------
> 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=1470&alloc_id638&op=CCk
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
|