罪と罰++二律背反

	// ドライバのドキュメントを参照
	String dbDriver = "com.mysql.jdbc.Driver";
	// 接続文字列
	String url= "jdbc:mysql://dbhost/xxxx";
	String dbuser = "ssuser";
	String dbpass = "ssuser";
	
	Connection conn = null;
	Statement stmt = null;
	ResultSet rs = null;
	
	String row = null;
	
	try {
		// ドライバをロードする
		// エラーになるときは、ドライバへのクラスパスを確認のこと
		Class.forName( dbDriver ).newInstance();
		
		// 接続
		conn = DriverManager.getConnection(url, dbuser, dbpass);
		stmt = conn.createStatement();
		
		// 問い合わせ
		rs = stmt.executeQuery("SELECT VERSION();");
		rs.next();
		row = rs.getString(1);
		
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		try {
			if (rs != null){
				rs.close();
			}
			if (stmt != null) {
				stmt.close();
			}
			if (conn != null) {
				conn.close();
			}
		}catch(Exception e) {
			
		}
	}

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2012-06-08 (金) 00:24:14 (4782d)