Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
A PreparedStatement enables you to create compiled SQL statements that execute more efficiently than Statements. PreparedStatements can also specify parameters, making them more flexible than Statements—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 " + "INNER JOIN Titles " + "ON AuthorISBN.ISBN=Titles.ISBN " + "WHERE LastName = ? AND FirstName = ?" ); |