Step 10.3: Write the code for the HelloHSQL class

Step 10.3: Write the code for the HelloHSQL class

click to expand

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 (                  {                  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.

click to expand
Figure 10.12: Source code entered into the editor pane.

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.

click to expand
Figure 10.13: Using the scroll bar to position the window to the top of the source.
click to expand
Figure 10.14: It's a larger source, so you'll have to scroll two or three times.

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.

click to expand
Figure 10.15: Using the Save tool to save the source.

You'll see the screen shown in Figure 10.16. You may skip ahead now to Step 10.5.

click to expand
Figure 10.16: The workbench after saving the new HelloHSQL source.

Eclipse: Step by Step (Step-by-Step series)
ISBN: 1583470441
EAN: 2147483647
Year: 2003
Pages: 90
Authors: Joe Pluta

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: