import java.sql.*; import java.io.*; import java.util.Date; public class BuildBeetlesTable { public static void main(String args[]) throws SQLException, IOException { System.out.print("\nLoading JDBC-ODBC driver...\n\n"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(ClassNotFoundException e) { System.exit( 1 ); } System.out.print("Connecting to Orders database...\n\n"); String url = "jdbc:odbc:Orders"; Connection conn = DriverManager.getConnection(url,"jia","ejzidsy1"); System.out.print("Building new Beetles table...\n\n"); String createString = "CREATE TABLE Beetles (name VARCHAR(35), " + "address VARCHAR(35), " + "city VARCHAR(20), " + "state VARCHAR(2), " + "zip VARCHAR(5), " + "email VARCHAR(30), " + "creditCard VARCHAR(15))"; Statement stmt = conn.createStatement(); stmt.executeUpdate(createString); System.out.print("Inserting test row in Beetles table...\n\n"); String insertString = "INSERT INTO Beetles VALUES ('Michael Owen', " + "'123 Elmwood Street', " + "'Lake Forest', " + "'IL', " + "'65431', " + "'mowen@aol.com', " + "'MasterCard')"; stmt.executeUpdate(insertString); ResultSet rset = stmt.executeQuery("SELECT * FROM Beetles"); while( rset.next() ) { System.out.print(" " + rset.getString( "name" ) + ", "); System.out.print(rset.getString( 2 ) + ", " ); System.out.print(rset.getString( 3 ) + ", " ); System.out.print(rset.getString( 4 ) + ",\n "); System.out.print(rset.getString( 5 ) + ", "); System.out.print(rset.getString( 6 ) + ", "); System.out.print(rset.getString( 7 ) + "\n"); } System.out.println("\nClosing database connection..."); conn.commit(); stmt.close(); rset.close(); conn.close(); } }