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 Statements

The easiest kind of SQL statements to use are DDL statements, including CREATE TABLE, ALTER TABLE, and DROP TABLE, and the DML statements INSERT, UPDATE, and DELETE—that is, everything except SELECT. SELECT, because it returns data—and sometimes a lot of data—will be covered in a later section.

To execute an SQL statement, we will first obtain a Statement object from our Connection object. Statement has a number of methods that let us execute an SQL statement. The easiest method to use for nonquery SQL statements is executeUpdate(). The following code, which assumes we have a valid Connection object, conn, demonstrates how we can create and populate a table with a row of data.

 Statement stmt = conn.createStatement(); ...

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