接続サンプルコード

 package jp.sample.myapp;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.Statement;
 
 public class Myapp {
     public static void main(String[] args) {
         try {
             Class.forName("org.postgresql.Driver");
             Connection conn = DriverManager.getConnection("jdbc:postgresql://my-dbserver01/mydb01", "db_user", "db_passwd");
             Statement stmt = conn.createStatement();
             ResultSet rs = stmt.executeQuery("SELECT * FROM t1");
             while (rs.next()) {
                 int id = rs.getInt("id");
                 System.out.println("ID: " + id);
             }
             rs.close();
             stmt.close();
             conn.close();
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 }

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS