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

public class JDBCInsert2 {
	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();
			}
		}

		try {
			stmt.addBatch("INSERT INTO EMPLOYEE VALUES('John', 'B', 'Smith', 123456789, '1965-01-09', '731 Fondren, Houston, TX', 'M', 30000, 333445555, 5);");
			stmt.addBatch("INSERT INTO EMPLOYEE VALUES('Franklin', 'T', 'Wong', 333445555, '1955-12-08', '638 Voss, Houston, TX', 'M', 40000, 888665555, 5);");
			stmt.addBatch("INSERT INTO EMPLOYEE VALUES('Alicia', 'J', 'Zelaya', 999887777, '1968-07-19', '3321 Castle, Spring, TX', 'F', 25000, 987654321, 4);");
			stmt.addBatch("INSERT INTO EMPLOYEE VALUES('Jennifer', 'S', 'Wallace', 987654321, '1941-06-20', '291 Berry, Bellaire, TX', 'F', 43000, 888665555, 4);");
			stmt.addBatch("INSERT INTO EMPLOYEE VALUES('Ramesh', 'K', 'Narayan', 666884444, '1962-09-15', '975 Fire Oak, Humble, TX', 'M', 38000, 333445555, 5);");
			stmt.addBatch("INSERT INTO EMPLOYEE VALUES('Joyce', 'A', 'English', 453453453, '1972-07-31', '5631 Rice, Houston, TX', 'F', 25000, 333445555, 5);");
			stmt.addBatch("INSERT INTO EMPLOYEE VALUES('Ahmad', 'V', 'Jabbar', 987987987, '1969-03-29', '980 Dallas, Houston, TX', 'M', 25000, 987654321, 4);");
			stmt.addBatch("INSERT INTO EMPLOYEE VALUES('James', 'E', 'Borg', 888665555, '1937-11-10', '450 Stone, Houston, TX', 'M', 55000, null, 1);");
			int[] insertCounts = stmt.executeBatch();
		} 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();
			}
		}
	}
}
