Source of BuildBeetlesTable.java


  1: import java.sql.*;
  2: import java.io.*;
  3: import java.util.Date;
  4: 
  5: public class BuildBeetlesTable {
  6:     public static void main(String args[])
  7:                                throws SQLException, IOException {
  8: 
  9:         System.out.print("\nLoading JDBC-ODBC driver...\n\n");
 10:         try {
 11:             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 12:         } catch(ClassNotFoundException e) {
 13:             System.exit( 1 );
 14:         }
 15:         System.out.print("Connecting to Orders database...\n\n");
 16:         String url = "jdbc:odbc:OrdersDriver";
 17:         Connection conn =
 18:                    DriverManager.getConnection(url,"rPasenko","mpf98eub");
 19:         System.out.print("Building new Beetles table...\n\n");
 20:         String createString =
 21:                   "CREATE TABLE Beetles (name VARCHAR(35), " +
 22:                                         "address  VARCHAR(35),  "  +
 23:                                         "city  VARCHAR(20),  "  +
 24:                                         "state  VARCHAR(2),  "  +
 25:                                         "zip  VARCHAR(5),  "  +
 26:                                         "email  VARCHAR(30),  "  +
 27:                                         "creditCard  VARCHAR(15))";
 28:         Statement stmt = conn.createStatement();
 29:         stmt.executeUpdate(createString);
 30:         System.out.print("Inserting test row in Beetles table...\n\n");
 31:         String insertString =
 32:                   "INSERT INTO Beetles VALUES ('Michael Owen', " +
 33:                                               "'123  Elmwood  Street',  "  +
 34:                                               "'Lake  Forest',  "  +
 35:                                               "'IL',  "  +
 36:                                               "'65431',  "  +
 37:                                               "'mowen@aol.com',  "  +
 38:                                               "'MasterCard')";
 39: 
 40:         stmt.executeUpdate(insertString);
 41:         ResultSet rset = stmt.executeQuery("SELECT * FROM Beetles");
 42:         while( rset.next() ) {
 43:             System.out.print("     " + rset.getString( "name" ) + ", ");
 44:             System.out.print(rset.getString( 2 ) + ", "  );
 45:             System.out.print(rset.getString( 3 ) + ", "  );
 46:             System.out.print(rset.getString( 4 ) + ",\n      ");
 47:             System.out.print(rset.getString( 5 ) + ", ");
 48:             System.out.print(rset.getString( 6 ) + ", ");
 49:             System.out.print(rset.getString( 7 ) + "\n");
 50:         }
 51:         System.out.print("\nClosing database connection...");
 52:         conn.commit();
 53:         stmt.close();
 54:         rset.close();
 55:         conn.close();
 56:     }
 57: }