Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package database;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class DataGet {
- static final String DB_URL = "jdbc:postgresql://localhost:5432/javaexample";
- // Database credentials
- static final String USER = "postgres";
- static final String PASS = "SQLMaster5";
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try {
- Connection con = DriverManager.getConnection(DB_URL, USER, PASS);
- if (con != null) {
- System.out.println("Heureka");
- con.createStatement();
- Statement stmt = null;
- String query = "select * from public.users";
- try {
- stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- while (rs.next()) {
- String lastname = rs.getString("password");
- System.out.println(lastname);
- }
- } catch (SQLException e ) {
- System.out.println(e.getMessage());
- } finally {
- if (stmt != null) { stmt.close(); }
- }
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement