A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Statement v/s PreparedStatement
Joined: Sep 17, 2009
Sep 23, 2009 02:27:10
PreparedStatement is called pre compiled statement but Statement is not why?
How PreparedStatement is pre compiled?
M K Rayapudi
Joined: Feb 19, 2007
Sep 23, 2009 03:36:52
In case of
, the skeleton of an SQL statement is prepared/compiled during it's creation/instantiation.
PreparedStatement ps = con.prepareStatement ("insert into EmpTable values(?,?,?)");
place holders (? marks) are used instead of actual values, this skeleton is compiled before going to execute with the actual values, as follows:
ps.setString(1,"1001"); ps.setString(2,"Abhijit"); ps.setString(3,"B.Tech"); ps.executeUpdate(); // here, the SQL statement doesn't require any comiplation, becuase its already compiled before
In case of
, no SQL statement is prepared/compiled during creation/instantiation.
Later, the SQL statement with values together executed as follows:
st.executeUpdate("insert into EmpTable values('1001','Abhijit','B.Tech')");
It is sorta covered in the
JavaRanch Style Guide
subject: Statement v/s PreparedStatement
pre-compile and prepared statement
statement Vs prepared statement for ordinary select queries
Diff b/w Statement and PreparedStatement
Tell me the main difference between Statement and PreparedStatement?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014