接続サンプルコード
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();
}
}
}