Advertisement
Guest User

Untitled

a guest
May 4th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. package main.updateprofile;
  2.  
  3. import main.utils.DBUtils;
  4.  
  5. import java.io.Serializable;
  6. import java.sql.Connection;
  7. import java.sql.PreparedStatement;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12.  
  13. public class UpdateProfileDAO implements Serializable {
  14.  
  15.     private List<UpdateProfileDTO> profile;
  16.  
  17.     public List<UpdateProfileDTO> getProfile() {
  18.         return profile;
  19.     }
  20.  
  21.     public void showProfile(String uname) throws SQLException, ClassNotFoundException {
  22.         Connection conn = null;
  23.         PreparedStatement stm = null;
  24.         ResultSet rs = null;
  25.  
  26.         try {
  27.             conn = DBUtils.makeConnection();
  28.             if (conn != null) {
  29.                 String query = "SELECT * FROM users WHERE username = ?";
  30.  
  31.                 stm = conn.prepareStatement(query);
  32.                 stm.setString(1,uname);
  33.  
  34.                 System.out.println(stm);
  35.                 rs = stm.executeQuery();
  36.  
  37.                 while (rs.next()) {
  38.                     String username = rs.getString("username");
  39.                     String password = rs.getString("password");
  40.                     String full_name = rs.getString("full_name");
  41.                     String email = rs.getString("email");
  42.                     String phone = rs.getString("phone");
  43.                     String role = rs.getString("role");
  44.  
  45.                     UpdateProfileDTO dto = new UpdateProfileDTO(username,password,full_name,email,phone,role);
  46.                     if (this.profile == null) {
  47.                         this.profile = new ArrayList<UpdateProfileDTO>();
  48.                     }
  49.                     this.profile.add(dto);
  50.                 }
  51.             }
  52.  
  53.         } finally {
  54.             if (rs != null) {
  55.                 rs.close();
  56.             }
  57.             if (stm != null) {
  58.                 stm.close();
  59.             }
  60.             if (conn != null) {
  61.                 conn.close();
  62.             }
  63.         }
  64.     }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement