カラムの追加と削除

/****************************/
/* カラムの追加と削除       */
/*      coded by Y.Suganuma */
/****************************/
import java.io.*;
import java.sql.*;

public class Test {

	public static void main(String args[]) {

		int i1;
		boolean s;
		ResultSet result;
		Connection Con;
					// JDBCドライバの登録
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		}
		catch (Exception e1) {
			System.out.println("Driver Error: " + e1.toString());
		}

		try {
					// データベースへの接続
			Con = DriverManager.getConnection("jdbc:mysql://cs-www/base?" + 
                  "useUnicode=true&characterEncoding=sjis", "xxxxx", "*****");
			try {
						// SQL の実行
				Statement SQL = Con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                                    ResultSet.CONCUR_UPDATABLE);
							// テーブルにデータを追加(ファイル test2.txt から)
				SQL.execute("LOAD DATA LOCAL INFILE \"test2.txt\" INTO TABLE gakuseki");

				SQL.execute("SELECT * FROM gakuseki");
				result = SQL.getResultSet();
				System.out.println("No, name, math");
				while (result.next()) {
					System.out.print("     ");
					for (i1 = 1; i1 <= 3; i1++) {
						if (i1 < 3)
							System.out.print(result.getString(i1) + ", ");
						else
							System.out.print(result.getString(i1));
					}
					System.out.println();
				}
						// カラム eng をカラム name の後ろに追加
				SQL.execute("ALTER TABLE gakuseki ADD eng INT(3) AFTER name");

				SQL.execute("SELECT * FROM gakuseki");
				result = SQL.getResultSet();
				System.out.println("No, name, math");
				while (result.next()) {
					System.out.print("     ");
					for (i1 = 1; i1 <= 4; i1++) {
						if (i1 < 4)
							System.out.print(result.getString(i1) + ", ");
						else
							System.out.print(result.getString(i1));
					}
					System.out.println();
				}
						// カラム eng を削除
				SQL.execute("ALTER TABLE gakuseki DROP eng");

				SQL.execute("SELECT * FROM gakuseki");
				result = SQL.getResultSet();
				System.out.println("No, name, math");
				while (result.next()) {
					System.out.print("     ");
					for (i1 = 1; i1 <= 3; i1++) {
						if (i1 < 3)
							System.out.print(result.getString(i1) + ", ");
						else
							System.out.print(result.getString(i1));
					}
					System.out.println();
				}
						// SQLを閉じる
		        SQL.close();
					// 接続を閉じる
				Con.close();
			}
			catch (SQLException e2) {
				System.out.println("SQL Error: " + e2.toString());
			}
		}
		catch (SQLException e3) {
			System.out.println("SQLException: " + e3.getMessage()); 
			System.out.println("SQLState: " + e3.getSQLState()); 
			System.out.println("VendorError: " + e3.getErrorCode()); 
		}
	}
}