import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; /** * @author mwood */ public class TestPostgresConnexion { public static void main(String[] args) { String url = "jdbc:postgresql://localhost:5433/testdb"; try { Class.forName("org.postgresql.Driver"); } catch (Exception e) { System.err.println("Failed to load JDBC implementation driver"); return; } try { Connection con = DriverManager.getConnection(url, "test_user", "test_password"); Statement select = con.createStatement(); // There happened to be a table called test_table in // my testdb database; use a suitable sql statement // for your situation. ResultSet result = select.executeQuery("select * from test_table"); while (result.next()) { System.out.println("result"); } select.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } } }