import java.io.*; import java.sql.*; /** * Creates and executes a simple SQL statement */ public class SimpleStatement { public static void main(String[] args) { Connection conn = null; Statement stmt = null; ResultSet rs = null; // Load the database driver. try { Class.forName("ORG.as220.tinySQL.textFileDriver"); } catch (ClassNotFoundException e) { System.out.println("Driver class was not found."); return; } // end try block // Connect to the database, create a SQL statement, execute it, // and print the results. try { conn = DriverManager.getConnection("jdbc:tinySQL", "", ""); stmt = conn.createStatement(); stmt.executeUpdate("INSERT INTO books (author, title, id) VALUES('Raymond Chandler', 'The Lady in the Lake', 10)"); rs = stmt.executeQuery("SELECT title, id FROM books WHERE author = 'Raymond Chandler'"); while (rs.next()) { System.out.print(rs.getString("title")); // get column with name System.out.println(" " + rs.getInt(2)); // get column with location in result set } } catch (SQLException eSQL) { System.out.println(eSQL.getMessage()); return; } finally { try { stmt.close(); conn.close(); } catch (Exception e) {} } // end try } // end main } // SimpleStatement