Using Prepared Statements

Up to this point, a java.sql.Statement class has been used to execute the SQL statements against the database. This is not very efficient if you will be executing the same SQL statements more than a couple of times because the SQL statement must be compiled each time it is sent to the database. The database does not understand the SQL string and is not able to execute it in the string format. It must turn the SQL string into something that it can understand and execute.

The java.sql.PreparedStatement can help with this because it will compile the SQL statement one time and then you can send the PreparedStatement to the database without the database having to compile it each time. This increases performance because the ...

Get Special Edition Using Java 2 Standard Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.