dbunit2

続き。

package hoge;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
* シンプルなコネクション管理クラス
*
* @author Shinji Miyamoto
*/
public class ConnectionManager {

final static String DRIVER = "com.mysql.jdbc.Driver";

final static String URL = "jdbc:mysql://localhost/blog?useUnicode=true&characterEncoding=SJIS";

final static String USER = "root";

final static String PASS = "";

public static Connection getConnection()
throws SQLException {

try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new IllegalStateException(
"fail to class load : "
+ e.getMessage());
}

Connection con = DriverManager.getConnection(URL,
USER, PASS);

return con;
}






/**
* 接続確認テスト用
*/
public static void main(String args)
throws SQLException {

Connection con = getConnection();
//テーブル一覧表示
ResultSet rs = con.getMetaData().getTables("", "",
"", new String { "TABLE" });
while (rs.next()) {
System.out.println(rs.getString("TABLE_NAME"));
}
con.close();
System.out.println("END");
}
}