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, ...
Get Building Scalable and High-Performance Java™ Web Applications Using J2EE™ Technology 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.