O'Reilly logo

Building Scalable and High-Performance Java™ Web Applications Using J2EE™ Technology by Greg Barish

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

Writing JDBC Queries

Building and executing JDBC queries is straightforward. The general process is to construct a Java Statement object (either statically or dynamically), execute it, and then iterate through the query results.

These are the only aspects of building queries that require a bit of thought:

  • Choosing the right kind of statement to construct

  • Distinguishing retrievals of data from updates to data

We'll see more detail about both of these issues shortly.

Processing a Statement

To construct a JDBC statement, we simply need to obtain a Statement object from a Connection object and then execute that statement using a valid SQL query. Say we want to query the first and last names of all employees in our database. For the sake of example, ...

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