Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. package ui.controller;
  2.  
  3. import domain.model.*;
  4. import java.sql.*;
  5. import java.util.*;
  6.  
  7. import javax.swing.JOptionPane;
  8.  
  9. import domain.db.*;
  10.  
  11. public class WebShopDbDemo {
  12. public static void main(String[] args) throws NumberFormatException, SQLException, ClassNotFoundException {
  13. Map<String, Person> records = new HashMap<String, Person>();
  14. Statement statement = null;
  15. Connection connection = null;
  16. Properties properties = new Properties();
  17. properties.setProperty("user", "r0663615");
  18. properties.setProperty("password", "gregeg");
  19. properties.setProperty("ssl", "true");
  20. properties.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
  21. boolean lus = true;
  22. while(lus){
  23. try{
  24. String input = JOptionPane.showInputDialog("Wat wilt u doen? \n1) Add person \n2) Overview \n3) Stop");
  25.  
  26. switch(input){
  27. case "1":
  28. try {
  29. String userid = JOptionPane.showInputDialog("Wat is de userid van de persoon?");
  30. String email = JOptionPane.showInputDialog("Wat is de email van de persoon?");
  31. String password = JOptionPane.showInputDialog("Wat is het passwoord van de persoon?");
  32. String firstname = JOptionPane.showInputDialog("Wat is de voornaam van de persoon?");
  33. String lastname = JOptionPane.showInputDialog("Wat is de naam van de persoon?");
  34. connection = DriverManager.getConnection("jdbc:postgresql://gegevensbanken.khleuven.be:51617/1TX31?currentSchema=r101112g12.person>", properties);
  35. statement = connection.createStatement();
  36. statement.execute("insert into r101112g12.person(userid, email, password, firstname, lastname) values('" + userid + "', '" + email + "', '" + password + "', '" + firstname + "', '" + lastname + "')");
  37. }
  38. catch(NullPointerException e){
  39. JOptionPane.showMessageDialog(null, e.getMessage());
  40. }
  41. catch(DomainException e){
  42. JOptionPane.showConfirmDialog(null, e.getMessage());
  43. }
  44. catch(IllegalArgumentException e){
  45. JOptionPane.showMessageDialog(null, e.getMessage());
  46. }
  47. catch(SQLException e){
  48. System.out.println(e.getMessage() + " ik heb aids.");
  49. }
  50. finally{
  51. try {
  52. statement.close();
  53. connection.close();
  54. } catch (SQLException e) {
  55. System.out.println(e.getStackTrace() + "ik heb aids3.");;
  56. }
  57. }
  58. break;
  59. case "2":
  60. try {
  61. connection = DriverManager.getConnection("jdbc:postgresql://gegevensbanken.khleuven.be:51617/1TX31?currentSchema=r101112g12.person>", properties);
  62. statement = connection.createStatement();
  63. ResultSet result = statement.executeQuery("select * from r101112g12.person");
  64. while(result.next()){
  65. String userid = result.getString("userid");
  66. String email = result.getString("email");
  67. String password = result.getString("password");
  68. String firstname = result.getString("firstname");
  69. String lastname = result.getString("lastname");
  70. Person person = new Person(userid, email, password, firstname, lastname);
  71. records.put(userid, person);
  72. }
  73. }
  74. catch(SQLException e){
  75. System.out.println(e.getMessage() + " ik heb aids.");
  76. }
  77. finally{
  78. try {
  79. statement.close();
  80. connection.close();
  81. } catch (SQLException e) {
  82. System.out.println(e.getStackTrace() + "ik heb aids3.");;
  83. }
  84. }
  85. for(Person person : records.values()){
  86. System.out.println(person.toString());
  87. }
  88. break;
  89. default:
  90. lus = false;
  91. JOptionPane.showMessageDialog(null, "Danku voor de applicatie te gebruiken.");
  92. }
  93. }
  94. catch(NullPointerException e){
  95. lus = false;
  96. JOptionPane.showMessageDialog(null, "Danku voor de applicatie te gebruiken.");
  97. }
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement