Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ui.controller;
- import domain.model.*;
- import java.sql.*;
- import java.util.*;
- import javax.swing.JOptionPane;
- import domain.db.*;
- public class WebShopDbDemo {
- public static void main(String[] args) throws NumberFormatException, SQLException, ClassNotFoundException {
- Map<String, Person> records = new HashMap<String, Person>();
- Statement statement = null;
- Connection connection = null;
- Properties properties = new Properties();
- properties.setProperty("user", "r0663615");
- properties.setProperty("password", "gregeg");
- properties.setProperty("ssl", "true");
- properties.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
- boolean lus = true;
- while(lus){
- try{
- String input = JOptionPane.showInputDialog("Wat wilt u doen? \n1) Add person \n2) Overview \n3) Stop");
- switch(input){
- case "1":
- try {
- String userid = JOptionPane.showInputDialog("Wat is de userid van de persoon?");
- String email = JOptionPane.showInputDialog("Wat is de email van de persoon?");
- String password = JOptionPane.showInputDialog("Wat is het passwoord van de persoon?");
- String firstname = JOptionPane.showInputDialog("Wat is de voornaam van de persoon?");
- String lastname = JOptionPane.showInputDialog("Wat is de naam van de persoon?");
- connection = DriverManager.getConnection("jdbc:postgresql://gegevensbanken.khleuven.be:51617/1TX31?currentSchema=r101112g12.person>", properties);
- statement = connection.createStatement();
- statement.execute("insert into r101112g12.person(userid, email, password, firstname, lastname) values('" + userid + "', '" + email + "', '" + password + "', '" + firstname + "', '" + lastname + "')");
- }
- catch(NullPointerException e){
- JOptionPane.showMessageDialog(null, e.getMessage());
- }
- catch(DomainException e){
- JOptionPane.showConfirmDialog(null, e.getMessage());
- }
- catch(IllegalArgumentException e){
- JOptionPane.showMessageDialog(null, e.getMessage());
- }
- catch(SQLException e){
- System.out.println(e.getMessage() + " ik heb aids.");
- }
- finally{
- try {
- statement.close();
- connection.close();
- } catch (SQLException e) {
- System.out.println(e.getStackTrace() + "ik heb aids3.");;
- }
- }
- break;
- case "2":
- try {
- connection = DriverManager.getConnection("jdbc:postgresql://gegevensbanken.khleuven.be:51617/1TX31?currentSchema=r101112g12.person>", properties);
- statement = connection.createStatement();
- ResultSet result = statement.executeQuery("select * from r101112g12.person");
- while(result.next()){
- String userid = result.getString("userid");
- String email = result.getString("email");
- String password = result.getString("password");
- String firstname = result.getString("firstname");
- String lastname = result.getString("lastname");
- Person person = new Person(userid, email, password, firstname, lastname);
- records.put(userid, person);
- }
- }
- catch(SQLException e){
- System.out.println(e.getMessage() + " ik heb aids.");
- }
- finally{
- try {
- statement.close();
- connection.close();
- } catch (SQLException e) {
- System.out.println(e.getStackTrace() + "ik heb aids3.");;
- }
- }
- for(Person person : records.values()){
- System.out.println(person.toString());
- }
- break;
- default:
- lus = false;
- JOptionPane.showMessageDialog(null, "Danku voor de applicatie te gebruiken.");
- }
- }
- catch(NullPointerException e){
- lus = false;
- JOptionPane.showMessageDialog(null, "Danku voor de applicatie te gebruiken.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement