import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class JDBCCreateTable {
	public static void main(String[] args) {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			System.err.println("Driver class not found");
			e.printStackTrace();
		}
		Connection con = null;

		try {
			con =
				(Connection) DriverManager.getConnection(
					"jdbc:mysql://localhost/jdbctest/",
					"mario",
					"thePassword");
		} catch (SQLException e1) {
			System.err.println("Error establishing database connection");
			Throwable t = e1;
			while (t != null) {
   			System.err.println("Type: " + t.getClass().getName());
      		System.err.println("Message: " + t.getMessage());
      		System.err.println("-----");
      		t = t.getCause();
			}
		}

		Statement  stmt = null;
		try {
			stmt = (Statement) con.createStatement();
		} catch (SQLException e2) {
			System.err.println("Error creating SQL-Statement");
			Throwable t = e2;
			while (t != null) {
   			System.err.println("Type: " + t.getClass().getName());
      		System.err.println("Message: " + t.getMessage());
      		System.err.println("-----");
      		t = t.getCause();
			}
		}
		String createTab = new String("CREATE TABLE EMPLOYEE(" +
			"FNAME VARCHAR(10) NOT NULL," +
			"MINIT VARCHAR(1)," +
			"LNAME VARCHAR(10) NOT NULL," +
			"SSN INTEGER(9) NOT NULL," +
			"BDATE DATE," +
			"ADDRESS VARCHAR(30)," +
			"SEX ENUM('M','F')," +
			"SALARY REAL(7,2) UNSIGNED," +
			"SUPERSSN INTEGER(9)," +
			"DNO INTEGER(1));");
		try {
			System.out.println("result="+stmt.executeUpdate(createTab));
		} catch (SQLException e3) {
			System.err.println("Error creating table EMPLOYEE");
			Throwable t = e3;
			while (t != null) {
   			System.err.println("Type: " + t.getClass().getName());
      		System.err.println("Message: " + t.getMessage());
      		System.err.println("-----");
      		t = t.getCause();
			}
		}
	}
}
