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

public class JDBCAlterTable {
	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("ALTER TABLE EMPLOYEE ADD PRIMARY KEY (SSN);");
		try {
			System.out.println("result=" + stmt.executeUpdate(createTab));
		} catch (SQLException e3) {
			System.err.println("Error altering 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();
			}
		}
	}
}
