Advertisement
Guest User

Untitled

a guest
May 15th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.14 KB | None | 0 0
  1. public void RegisterCustomer() {
  2.        
  3.         try {
  4.             // recreate the connection if needed
  5.             if (this.connect == null || this.connect.isClosed()) {
  6.                 // change the DB Path
  7.                 this.connect = DriverManager.getConnection("jdbc:sqlite:Application.db");
  8.             }
  9.             //recreate the statement if needed
  10.             if (this.statement == null || this.statement.isClosed()) {
  11.                 this.statement = this.connect.createStatement();
  12.             }
  13.  
  14.         } catch (SQLException e) {
  15.             System.out
  16.                     .println("Failed to connect to the database");
  17.             throw new RuntimeException(e);
  18.         }
  19.        
  20.         String username = user.getText();
  21.         char[] pass = password.getPassword();
  22.         String password = new String(pass);
  23.         char[] passConfirm = confirmPass.getPassword();
  24.         String passwordConfirm = new String(passConfirm);
  25.         String firstName = FirstName.getText();
  26.         String lastName = LastName.getText();
  27.         String email = Email.getText();
  28.         int age = Integer.parseInt(Age.getText());
  29.        
  30.        
  31.        
  32.        
  33.         try {
  34.             PreparedStatement preparedStatement = this.connect.prepareStatement("INSERT INTO CUSTOMER (USERNAME, PASSWORD, FIRSTNAME, LASTNAME, EMAIL, AGE) VALUES (?,?,?,?,?,?)");
  35.             preparedStatement.setString(1, username);
  36.             preparedStatement.setString(2, password);
  37.             preparedStatement.setString(3, firstName);
  38.             preparedStatement.setString(4, lastName);
  39.             preparedStatement.setString(5, email);
  40.             preparedStatement.setInt(6, age);
  41.         }
  42.         catch (Exception e) {
  43.                 System.out.println("Error retrieving customer information");
  44.                 throw new RuntimeException(e);
  45.         }
  46.     }
  47.        
  48.         public void RegisterSeller() {
  49.            
  50.             try {
  51.                 // recreate the connection if needed
  52.                 if (this.connect == null || this.connect.isClosed()) {
  53.                     // change the DB Path
  54.                     this.connect = DriverManager.getConnection("jdbc:sqlite:Application.db");
  55.                 }
  56.                 //recreate the statement if needed
  57.                 if (this.statement == null || this.statement.isClosed()) {
  58.                     this.statement = this.connect.createStatement();
  59.                 }
  60.  
  61.             } catch (SQLException e) {
  62.                 System.out
  63.                         .println("Failed to connect to the database");
  64.                 throw new RuntimeException(e);
  65.             }
  66.            
  67.             String username = user.getText();
  68.             char[] pass = password.getPassword();
  69.             String password = new String(pass);
  70.             char[] passConfirm = confirmPass.getPassword();
  71.             String passwordConfirm = new String(passConfirm);
  72.             String firstName = FirstName.getText();
  73.             String lastName = LastName.getText();
  74.             String email = Email.getText();
  75.             int age = Integer.parseInt(Age.getText());
  76.            
  77.            
  78.            
  79.            
  80.             try {
  81.                 PreparedStatement preparedStatement = this.connect.prepareStatement("INSERT INTO SELLER (USERNAME, PASSWORD, FIRSTNAME, LASTNAME, EMAIL, AGE) VALUES (?,?,?,?,?,?)");
  82.                 preparedStatement.setString(1, username);
  83.                 preparedStatement.setString(2, password);
  84.                 preparedStatement.setString(3, firstName);
  85.                 preparedStatement.setString(4, lastName);
  86.                 preparedStatement.setString(5, email);
  87.                 preparedStatement.setInt(6, age);
  88.             }
  89.             catch (Exception e) {
  90.                     System.out.println("Error retrieving customer information");
  91.                     throw new RuntimeException(e);
  92.             }
  93.            
  94.  
  95.        
  96.        
  97.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement