Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. package lib;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. import org.postgresql.ds.PGSimpleDataSource;
  9.  
  10. public class Databazy {
  11.  
  12.  
  13. public static void main(String[] args) throws SQLException {
  14. PGSimpleDataSource dataSource = new PGSimpleDataSource();
  15. dataSource.setServerName("db.dai.fmph.uniba.sk");
  16. dataSource.setPortNumber(5432);
  17. dataSource.setDatabaseName("playground");
  18. dataSource.setUser("mizerik1@uniba.sk");
  19. dataSource.setPassword("jozko123");
  20. try(Connection con = dataSource.getConnection()) {
  21. try(Statement s = con.createStatement()) {
  22. //s.executeQuery("SELECT import_company()");
  23. try(ResultSet r = s.executeQuery("select employee_id, first_name, last_name from employees")){
  24. while(r.next()) {
  25. int employeeId = r.getInt(1);
  26. String firstName = r.getString(2);
  27. String lastName = r.getString(3);
  28. System.out.println(employeeId + " " + firstName + " " + lastName);
  29. }
  30. }
  31. }
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement