[Advanced-java] Memory consumption & performance
Lothar Kimmeringer
adv-java at kimmeringer.de
Mon Apr 3 22:45:07 PDT 2006
Marco Ferretti wrote:
> I am i the web scenario : there is a client that wants to upload one or more
> files and I _have_ to record them in a database ( the real file, not the
> position and write the file somewhere in the filesystem ) . I am using
> Jakarta commons.fileupload libs to get the data from the client; a servlet ,
> then, creates an SQL string using a StringBuffer. Now, since the client can
> upload more than one file at the time I was wondering, in a production state,
> wether of using StringBuffer.delete() or simply a new StringBuffer is the
> best approach towards memory consumption & performance ... or if there's a
> better way to do it .
If the statement itself is always the same, like
insert into mytable (col1, col2, col3, col4) values (...)
where only the values-part is changing, you should use
PreparedStatement instead of Statement. Not only you can
use the same SQL-Statement all the time (with ? instead
of the concrete values), it's the only way of inserting
larger blocks of data into the database (using BLOBs or
CLOBs).
In addition to this most JDBC-drivers cache the result
of the parsing of the SQL-statement, so subsequent calls
of the same statement will perform faster than the first
call.
> I don't think that there will be much difference between using statements or
> prepared statements ... am I wrong ?
I think you're wrong.
Regards, Lothar
--
Lothar Kimmeringer E-Mail: spamfang at kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!
More information about the Advanced-java
mailing list