Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main.updateprofile;
- import main.utils.DBUtils;
- import java.io.Serializable;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- public class UpdateProfileDAO implements Serializable {
- private List<UpdateProfileDTO> profile;
- public List<UpdateProfileDTO> getProfile() {
- return profile;
- }
- public void showProfile(String uname) throws SQLException, ClassNotFoundException {
- Connection conn = null;
- PreparedStatement stm = null;
- ResultSet rs = null;
- try {
- conn = DBUtils.makeConnection();
- if (conn != null) {
- String query = "SELECT * FROM users WHERE username = ?";
- stm = conn.prepareStatement(query);
- stm.setString(1,uname);
- System.out.println(stm);
- rs = stm.executeQuery();
- while (rs.next()) {
- String username = rs.getString("username");
- String password = rs.getString("password");
- String full_name = rs.getString("full_name");
- String email = rs.getString("email");
- String phone = rs.getString("phone");
- String role = rs.getString("role");
- UpdateProfileDTO dto = new UpdateProfileDTO(username,password,full_name,email,phone,role);
- if (this.profile == null) {
- this.profile = new ArrayList<UpdateProfileDTO>();
- }
- this.profile.add(dto);
- }
- }
- } finally {
- if (rs != null) {
- rs.close();
- }
- if (stm != null) {
- stm.close();
- }
- if (conn != null) {
- conn.close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement