q 10.3(a) Enter the source code below after the comments.
import java.sql.*; public class HelloHSQL { private static final String SQLCLASS = "org.hsqldb.jdbcDriver"; private static final String SQLURL = "jdbc:hsqldb:hsqldb"; private static final String SQLUSER = "sa"; private static final String SQLPWD = ""; public static void main(String[] args) { try { // Create a connection Class.forName (SQLCLASS); Connection c = DriverManager.getConnection(SQLURL, SQLUSER, SQLPWD); Statement s = c.createStatement(); // Delete and recreate the table try { s.execute("DROP TABLE ITEMS"); } catch (Exception e) {} s.execute("CREATE TABLE ITEMS (ItemNumber CHAR, Description CHAR)"); // Insert data s.execute("INSERT INTO ITEMS VALUES ('DOG', 'Cuddly Duddly')"); s.execute("INSERT INTO ITEMS VALUES ('CAT', 'Felix the Cat')"); s.execute("INSERT INTO ITEMS VALUES ('OCTOPUS', 'Squidworth')"); // Check the results ResultSet rs = s.executeQuery("SELECT * FROM ITEMS"); while (rs.next()) { System.out.println( "Item: " + rs.getString("ItemNumber") + ", Description: " + rs.getString("Description")); } // Shut down s.close(); c.close(); } catch (Exception e) { System.out.println("Error: " + e); } // When done, clean up resource and exit System.exit(0); } }
At this point, your screen will look like the one in Figure 10.12.
Use the scroll bar to reposition the source window to the top of the code. You can also use standard editing keystrokes, such as Ctrl-Home.
q 10.3(b) Position window to top of source.
Now save the source. You can use the Save tool on the main Eclipse tool bar, Ctrl-S, or the editor popup menu. I'll use the Save tool:
q 10.3(c) Click on the Save icon on the tool bar.
You'll see the screen shown in Figure 10.16. You may skip ahead now to Step 10.5.