O'Reilly logo

Java™ Oracle® Database Development by David J. Gallardo

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

Executing SQL Queries

The most commonly used SQL statement is the SELECT statement. We can execute SELECT statements using either a Statement or a PreparedStatement object. Both Statement and PreparedStatement have a method, executeQuery(), that executes an SQL SELECT command and returns a ResultSet containing the results of the query in the form of a table. Consider this query using Statement:

Statement stmt = new conn.getStatement();
ResultSet rs = stmt.executeQuery(
   "SELECT ENAME, JOB, SAL FROM EMP");

The ResultSet that this example returns contains three columns, ENAME, JOB, and SAL, as specified in the select list. Assuming the database hasn't been altered since Oracle was installed, it will contain 14 rows.

Navigating a ResultSet

We access ...

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