import java.sql.*; import java.io.*; import java.util.*; public class HelloWorldAJDBC { public static void main(String[] args) { try { Properties prop = new Properties(); // プロパティファイルから名前と値のリストを読み込みます prop.load(new FileInputStream("javahellojdbc.properties")); // 値を取得します String driver = prop.getProperty("javahello.jdbc.driver"); String url = prop.getProperty("javahello.jdbc.url"); String user = prop.getProperty("javahello.jdbc.user"); String password = prop.getProperty("javahello.jdbc.password"); // ドライバクラスをロード Class.forName(driver); // データベースへ接続 Connection con = DriverManager.getConnection(url,user,password); // ステートメントオブジェクトを生成 Statement stmt = con.createStatement(); String sql = "SELECT * FROM HELLO_WORLD_TABLE"; // クエリーを実行して結果セットを取得 ResultSet rs = stmt.executeQuery(sql); // 検索された行数分ループ while(rs.next()){ // NOを取得 int no = rs.getInt("NO"); // 言語を取得 String lang = rs.getString("LANGUAGE"); // メッセージを取得 String msg = rs.getString("MESSAGE"); // 表示 System.out.println(no + " " + lang + " " + msg); } // データベースから切断 stmt.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } } }