Guest User

Untitled

a guest
Jan 14th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.20 KB | None | 0 0
  1. @Override
  2.     public User getUser(String login) throws DAOException{
  3.        
  4.         PreparedStatement ps = null;
  5.         Connection con = null;
  6.         ResultSet rs = null;
  7.         User user = null;
  8.        
  9.         try{
  10.            
  11.             con = ConnectionPool.getInstance().getConnection();
  12.            
  13.             ps = con.prepareStatement(CommonRequest.GET_USER);
  14.            
  15.             ps.setString(1,login);
  16.            
  17.             rs = ps.executeQuery();
  18.            
  19.             if(rs.next()){
  20.                 user = new User(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getBoolean(5) ,rs.getInt(6));
  21.  
  22.             }  
  23.            
  24.         }catch (ConnectionPoolException e) {
  25.             throw new DAOException("Get connection error", e);
  26.            
  27.         }catch (SQLException e) {
  28.             throw new DAOException("SQL Getting user exception", e);
  29.            
  30.         }  finally {
  31.             if (rs != null) {
  32.                 try {
  33.                     rs.close();
  34.                 } catch (SQLException e) {
  35.                     logger.error("Close rs trouble");
  36.                 }
  37.             }
  38.             if (ps != null) {
  39.                 try {
  40.                     ps.close();
  41.                 } catch (SQLException e) {
  42.                     logger.error("Close ps trouble");
  43.                 }
  44.             }
  45.             if (con != null) {
  46.                 try {
  47.                     ConnectionPool.getInstance().returnConnection(con);
  48.                 } catch (ConnectionPoolException e) {
  49.                     logger.error("Return con error");
  50.                 }
  51.             }
  52.         }
  53.         return user;
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment