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

public class JDBCUpdate2 {
	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;
		PreparedStatement pstmt = null;
		try {
			stmt = (Statement) con.createStatement();
			pstmt = (PreparedStatement) con.prepareStatement("UPDATE EMPLOYEE SET BDAY=? WHERE DAYOFWEEK(BDATE)=?;");

		} 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();
			}
		}

		try {
			String[] days={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"} ;
			stmt.addBatch("ALTER TABLE EMPLOYEE ADD BDAY VARCHAR(10);");
			for (int i=1; i<8;i++){
				pstmt.setString(1,days[i-1]);
				pstmt.setInt(2,i);
				pstmt.addBatch();
			}
			int[] result = stmt.executeBatch();
			for (int i=0; i<result.length;i++){
				System.out.println("Statement No "+i+" changed "+result[i]+" rows");
			}
		} catch (SQLException e3) {
			System.err.println("Error inserting values into 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();
			}
		}
	}
}
