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