import java.util.Calendar;
import java.sql.*;
import java.io.*;

class ModifyBeetlesTable {
    public static void main( String args[] )
                       throws SQLException, IOException {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch(ClassNotFoundException e) {
            System.exit(1);
        }
        System.out.print("\nConnecting to Beetles table...\n\n");
        String url = "jdbc:odbc:OrdersDriver";
        Connection conn =
                DriverManager.getConnection(url,"rPasenko","mpf98eub");
        Statement stmt = conn.createStatement();
        System.out.print("Modifying Beetles table...\n\n");
        String updateString =
                "ALTER TABLE Beetles ADD ORDERNO VARCHAR(12)";
        stmt.executeUpdate(updateString);
        Calendar cal = Calendar.getInstance();
        String orderNo = String.valueOf(cal.get(cal.MONTH)+1) +
                                        String.valueOf(cal.get(cal.DAY_OF_MONTH)) +
                                        String.valueOf(cal.get(cal.YEAR)) +
                                        String.valueOf(cal.get(cal.HOUR)) +
                                        String.valueOf(cal.get(cal.MINUTE)) +
                                        String.valueOf(cal.get(cal.SECOND));
        updateString = "UPDATE Beetles SET ORDERNO = " +
                                     orderNo + " WHERE NAME='Michael  Owen'";
        stmt.executeUpdate(updateString);
        ResultSet rset = stmt.executeQuery("SELECT * FROM Beetles");
        System.out.print("Displaying  table  contents...\n\n");
        while (rset.next()) {
            System.out.println("     " +
                       rset.getString("name") + ", " +
                       rset.getString("address") + ", " +
                       rset.getString("city") + ", " +
                       rset.getString("state") + "\n     " +
                       rset.getString("zip") + ", " +
                       rset.getString("email") + ", " +
                       rset.getString("creditCard") + ", " +
                       rset.getString("orderno") );
        }
        System.out.print("\nDeleting test record...\n\n");
        updateString = "DELETE FROM Beetles WHERE NAME='Michael Owen'";
        stmt.executeUpdate(updateString);
        System.out.print("Closing connection...\n\n");
        conn.commit();
        stmt.close();
        rset.close();
        conn.close();
    }
}