Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package db_03;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.sql.SQLException;
- class JdbcTestPostgreSQL {
- public static void main (String args[]) {
- try {
- Class.forName("org.postgresql.Driver");
- } catch (ClassNotFoundException e) {
- System.err.println (e);
- System.exit (-1);
- }
- try {
- Connection connection = DriverManager.getConnection(
- //"jdbc:postgresql://dbhost:port/dbname", "user", "dbpass");
- "jdbc:postgresql://manny.db.elephantsql.com:5432/ksvjamlu", "ksvjamlu", "4KG94E-KSp0BLVFbv2oQrP3JnF0eOUBb");
- // build query, here we get info about all databases"
- String query = "SELECT * FROM movies";
- // execute query
- Statement statement = connection.createStatement ();
- ResultSet rs = statement.executeQuery (query);
- // return query result
- while ( rs.next () )
- // display table name
- System.out.println ("PostgreSQL Query result: " + rs.getString (2) + " : " + rs.getString(3) + " : " + rs.getString(1));
- connection.close ();
- }
- catch (SQLException e) {
- System.err.println (e);
- System.exit (-1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement