Originally posted by Jeanne Boyarsky:
Vinod,
For example, the first query could use an index (if there is one) and not touch the table at all.
Here I don't understand something, the index is used mostly for the WHERE clause filter, why should two queries with same WHERE clause execute differently (in terms index usage), or you mean it is up to the DB query optimizer to decide what to do what query ?.
Another question
How different is preparing a statement in the below two code
1) connection.prepareStatement("select * from table where col1=1");
2) stmt = connection.prepareStatement("select * from table where col1=?");
stmt.setInt(1,1);
I know in the earlier version of
JDBC, where the compiled prepared statements where cached on a connection, the first one is inefficient because each execution of the prepared statenemt is considered as different one. In the recent version of JDBC this "facility" is no longer there (except when you use some application servers), so does the above optimization still holds.