thanks very much for your answer. Yes I added some println statements, and when I got a list (the ArrayList) of 2 objects, it print 2 times, so it's being called twice. But only one is being saved effectively(only the first one). That's very strange to me.
Oh nice, I really like suggestions from the experts I never tried using this executeBatch() method, is it the same? Instead of executeUpdate I put executeBatch() ?
I know in lots of applications they use Hibernate (and I'd really wanted to use...) but do you know any good "architecture" of this DAO thing. Something like creating a Singleton of Connection, etc. Something to optimize the performance.
William, If it is printing twice, it is surprising that it isn't saving twice. Two thoughts: 1) The two entries have different values right? One thing you can do is look at the result of executeUpdate(). It returns an int array with a value for each requested update. 2) Is it possible some other method is using ps since it is instance variable? That could mess things up.
Here's an example of batching:
Using executeBatch does optimize the use of the connection because it passes the data in one trip.
Joined: Jul 21, 2008
Hmm, I tried that two items you suggested, no changes at all.
Both times it prints 1. But still, only one line is saved in the database.