24.8 PreparedStatements
A PreparedStatement enables you to create compiled SQL statements that execute more efficiently than Statement
s. PreparedStatement
s can also specify parameters, making them more flexible than Statement
s—you can execute the same query repeatedly with different parameter values. For example, in the books
database, you might want to locate all book titles for an author with a specific last and first name, and you might want to execute that query for several authors. With a PreparedStatement
, that query is defined as follows:
PreparedStatement authorBooks = connection.prepareStatement( "SELECT LastName, FirstName, Title " + "FROM Authors INNER JOIN AuthorISBN " + "ON Authors.AuthorID=AuthorISBN.AuthorID ...
Get Java™ How To Program (Early Objects), Tenth 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.