Advertisement
Guest User

Untitled

a guest
Sep 11th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. package com.scoresystem;
  2.  
  3. import java.sql.*;
  4.  
  5. public class User {
  6.  
  7.  
  8.     private String iid;
  9.     private String id;
  10.     private String fullName;
  11.     private String password;
  12.     private String type;
  13.     private Date createdAt;
  14.     private Date updatedAt;
  15.     private String createdBy;
  16.     private String updatedBy;
  17.  
  18.     /*
  19.  
  20.     User user = new User();
  21.     user.where("iid", "23kj-3fDds-ft4fd-3fdf3-98f9");
  22.  
  23.  
  24.  
  25.      */
  26.  
  27.  
  28.  
  29.  
  30.     public void where(String key, String value){
  31.         try{
  32.             Class.forName("com.mysql.jdbc.Driver");
  33.  
  34.             //create connection
  35.             Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/scoresSystem",
  36.                     "root" ,
  37.                     "1");
  38.  
  39.             Statement s = c.createStatement();
  40.             ResultSet result = s.executeQuery("SELECT * FROM Users WHERE " + key + "=" + value + ";");
  41.             while(result.next()) {
  42.                 this.iid = result.getString("IID");
  43.                 this.id = result.getString("ID");
  44.                 this.fullName = result.getString("fullName");
  45.                 this.password = result.getString("password");
  46.                 this.type = result.getString("type");
  47.                 this.updatedAt = new Date(result.getTimestamp("updatedAt") != null ? result.getTimestamp("updatedAt").getTime());
  48.                 this.createdAt = new Date(result.getTimestamp("createdAt").getTime());
  49.                 this.createdBy = result.getString("createdBy");
  50.                 this.updatedBy = result.getString("updatedBy");
  51.             }
  52.             c.close();
  53.  
  54.  
  55.  
  56.         }catch(SQLException ex){
  57.  
  58.             ex.printStackTrace();
  59.         } catch (ClassNotFoundException e) {
  60.             e.printStackTrace();
  61.         }
  62.  
  63.  
  64.  
  65.     }
  66.  
  67.     public String getIid() {
  68.         return iid;
  69.     }
  70.     public String getId() {
  71.         return id;
  72.     }
  73.     public String getFullName() {
  74.         return fullName;
  75.     }
  76.  
  77.     public String getType() {
  78.         return type;
  79.     }
  80.  
  81.     public Date getCreatedAt() {
  82.         return createdAt;
  83.     }
  84.  
  85.     public Date getUpdatedAt() {
  86.         return updatedAt;
  87.     }
  88.  
  89.     public String getCreatedBy() {
  90.         return createdBy;
  91.     }
  92.  
  93.     public String getUpdatedBy() {
  94.         return updatedBy;
  95.     }
  96.  
  97.  
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement