Vince <> wrote:
>I must say at this point that every message has a variable length and
>thus variable amount of data/fields that must be returned to the DB.
>
>During a workshop I got an argue with another developer because he said
>we should use PrepareStatements instead of normal Statements, they've
>got a better performance - compiling once on DB Server.
He's right. The other MAJOR advantage you get is automatic quoting. If
you're executing statments via string concatenation, you have to deal with crap
like quotes and SQL reserved words in the data.
>We basically better concatenate the Insert Statement once for
>each row of data and then use a batch and commit it to the DB...
....
>My question now: How would you solve it? Would the PrepareStatement
>still improve the performance, considering though the variable amount of
>columns?
I'd still plan on using as few distinct statements, even if it means you have
a number of messages that are explicitly inserting nulls as opposed to
generating a custom insert that ignores irrelevant columns (which still
inserts nulls). Even if you generate them by concatenation, you can make use
of caching - Oracle and some others will only have to do a soft-parse rather
than a full parse if the text of the statement is identical to one in
the cache. C3p0 or other pooling system will do client-side caching based
on string comparisons.
--
Mark Rafn
<http://www.dagon.net/>