Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. package ui.ui;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.Properties;
  9.  
  10. import db.DbException;
  11. import domain.Person;
  12.  
  13. public class DatabaseApp {
  14.  
  15.  
  16. public static void main(String[] args) throws SQLException{
  17.  
  18. String url = "jdbc:postgresql://gegevensbanken.khleuven.be:51617/1TX34?currentSchema=r0667009_Web3";
  19. Properties properties = new Properties();
  20. properties.setProperty("user", "r0667009");
  21. properties.setProperty("password", "johnisnedikkevettehomow");
  22. properties.setProperty("ssl", "true");
  23. properties.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
  24.  
  25. try(Connection connection = DriverManager.getConnection(url, properties);
  26.  
  27. Statement statement = connection.createStatement();)
  28.  
  29.  
  30.  
  31. {
  32.  
  33. ResultSet result = statement.executeQuery("SELECT * FROM person");
  34.  
  35. while(result.next())
  36. {
  37. String id = result.getString("userid");
  38. String email = result.getString("email");
  39. String password = result.getString("password");
  40. String firstName = result.getString("firstName");
  41. String lastName = result.getString("lastName");
  42.  
  43. Person person = new Person(id, email, password, firstName, lastName);
  44. System.out.println(person);
  45. }
  46.  
  47. }
  48. catch(SQLException e)
  49. {
  50. throw new DbException("Database error", e);
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. }
  59.  
  60.  
  61.  
  62.  
  63. }
  64.  
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement