Executing Dynamic SQL

SQL statements can be submitted to the database for execution. The simplest form of SQL statement to handle within an application is a Data Manipulation Language (DML) statement, such as INSERT, UPDATE, or DELETE. Such statements return no rows from the database. With DML, the program is either creating or operating on an object. An SQLException will be raised if there is an error in executing the statement.

The following code fragment will issue a SET SCHEMA statement to the database for execution:

Connection conn = null;
Statement stmt = null;

try {
  conn = DriverManager.getConnection("jdbc:derby:YMLD"); 
  stmt = conn.createStatement(); 
  stmt.execute("set schema 'APP'");  
}

The stmt.execute method will immediately execute ...

Get Apache Derby—Off to the Races: Includes Details of IBM® Cloudscape™ 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.