/******************************************/ /* データベースの作成,選択,および,削除 */ /* coded by Y.Suganuma */ /******************************************/ import java.io.*; import java.sql.*; public class Test { public static void main(String args[]) { 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/mysql?" + "useUnicode=true&characterEncoding=sjis", "xxxxx", "*****"); try { // SQL の実行 Statement SQL = Con.createStatement(); // データベースの作成 SQL.execute("CREATE DATABASE base"); // データベースの選択 SQL.execute("USE base"); // データベースの削除 SQL.execute("DROP DATABASE base"); // 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()); } } }