Use a Statement object to run an SQL statement and optionally obtain the ResultSet produced by it.
PreparedStatement inherits from Statement, and CallableStatement inherits from PreparedStatement. Use the following Statement objects to run different SQL statements:
The Statement object allows you to submit multiple update commands as a single group to a database through the use of a batch update facility. Through the use of the batch update facility, you may get better performance because it is usually faster to process a group of update operations than to process one update operation at a time. If you want to use the batch update facility, you need JDBC 2.0 and JDK 1.2.
When using batch updates, usually you should turn off auto-commit. Turning off auto-commit allows your program to determine whether to commit the transaction if an error occurs and not all of the commands have executed. In JDBC 2.0, a Statement object can keep track of a list of commands that can be successfully submitted and executed together in a group. When this list of batch commands is executed by the executeBatch() method, the commands are executed in the order in which they were added to the list.
Use Connection.createStatement() to create new Statement objects.
The following example shows how to use a Statement object.
// Connect to the AS/400. Connection c = DriverManager.getConnection("jdbc:as400://mySystem"); // Create a Statement object. Statement s = c.createStatement(); // Run an SQL statement that creates // a table in the database. s.executeUpdate("CREATE TABLE MYLIBRARY.MYTABLE (NAME VARCHAR(20), ID INTEGER)"); // Run an SQL statement that inserts // a record into the table. s.executeUpdate("INSERT INTO MYLIBRARY.MYTABLE (NAME, ID) VALUES ('DAVE', 123)"); // Run an SQL statement that inserts // a record into the table. s.executeUpdate("INSERT INTO MYLIBRARY.MYTABLE (NAME, ID) VALUES ('CINDY', 456)"); // Run an SQL query on the table. ResultSet rs = s.executeQuery("SELECT * FROM MYLIBRARY.MYTABLE"); // Close the Statement and the // Connection. s.close(); c.close();