Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

About PreparedStatement's performance

843859Sep 13 2005 — edited Sep 21 2005
Hi all.

I heard about PreparedStatement's performance in this cases:
            PreparedStatement ps = c.prepareStatement("update people set first_name = ?, last_name = ?, gender = ?, email = ? where id_people = ?");
            while(au.hasNext()) {
                     ps.setString(1,first_name);
                     ps.setString(2, last_name);
                     ps.setString(3, gender);
                     ps.setString(4, email);
                     ps.setInt(5, id);
            }
one of the advantages is that the PreparedStatement is only compiled once and the query is executed N-times... but, what's the performance difference in this case:
            PreparedStatement ps = null;
            while(au.hasNext()) {
                     ps = c.prepareStatement("update people set first_name = ?, last_name = ?, gender = ?, email = ? where id_people = ?");
                     ps.setString(1,first_name);
                     ps.setString(2, last_name);
                     ps.setString(3, gender);
                     ps.setString(4, email);
                     ps.setInt(5, id);
            }
other questions emerge in my head, if i redefine a PreparedStatement for example:
            PreparedStatement ps = c.preparedStatement("insert into bla bla");
            ps.executeUpdate();
            while(au.hasNext()) {
                    if(odd) {
                         ps = c.prepareStatement("insert into bla bla bla");
                         ps.executeUpdate();
                    } else {
                         ps = c.prepareStatement("delete from bla bla bla");
                         ps.executeUpdate();
                    }
                    ps = c.prepareStatement("select from bla bla bla");
                    rs = ps.executeQuery();
            }
I will apreciate all your comments about this,

Kind regards.

JAEC
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 19 2005
Added on Sep 13 2005
6 comments
96 views