Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.scoresystem;
- import java.sql.*;
- public class User {
- private String iid;
- private String id;
- private String fullName;
- private String password;
- private String type;
- private Date createdAt;
- private Date updatedAt;
- private String createdBy;
- private String updatedBy;
- /*
- User user = new User();
- user.where("iid", "23kj-3fDds-ft4fd-3fdf3-98f9");
- */
- public void where(String key, String value){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- //create connection
- Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/scoresSystem",
- "root" ,
- "1");
- Statement s = c.createStatement();
- ResultSet result = s.executeQuery("SELECT * FROM Users WHERE " + key + "=" + value + ";");
- while(result.next()) {
- this.iid = result.getString("IID");
- this.id = result.getString("ID");
- this.fullName = result.getString("fullName");
- this.password = result.getString("password");
- this.type = result.getString("type");
- this.updatedAt = new Date(result.getTimestamp("updatedAt") != null ? result.getTimestamp("updatedAt").getTime());
- this.createdAt = new Date(result.getTimestamp("createdAt").getTime());
- this.createdBy = result.getString("createdBy");
- this.updatedBy = result.getString("updatedBy");
- }
- c.close();
- }catch(SQLException ex){
- ex.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- public String getIid() {
- return iid;
- }
- public String getId() {
- return id;
- }
- public String getFullName() {
- return fullName;
- }
- public String getType() {
- return type;
- }
- public Date getCreatedAt() {
- return createdAt;
- }
- public Date getUpdatedAt() {
- return updatedAt;
- }
- public String getCreatedBy() {
- return createdBy;
- }
- public String getUpdatedBy() {
- return updatedBy;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement