O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting ready

An object of PreparedStatement--a subinterface of Statement--can be precompiled and stored in the database and then used to efficiently execute the SQL statement multiple times for different input values. Similar to an object of Statement (created by the createStatement() method), it can be created by the prepareStatement() method of the same Connection object. 

 There is also a third version of a statement that creates a method called prepareCall() that, in turn, creates the CallableStatement object used to execute a database-stored procedure, but we will discuss this in a separate recipe later.

The same SQL statement that was used to generate Statement can be used to generate PreparedStatement too. In fact, it is a good idea ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required