1    package com.instantbank.collections.ach;
2    
3    import java.sql.Connection;
4    import java.sql.PreparedStatement;
5    import java.sql.ResultSet;
6    import java.sql.SQLException;
7    import com.instantbank.collections.util.DataAccess;
8    import com.instantbank.collections.util.InstantbankException;
9    import com.instantbank.collections.util.SqlUtil;
10   
11   public class UserDAO extends Object {
12     public UserDAO() {
13       super();
14     }
15     // Sql prepared statement constants
16   
17     private static final String RETRIEVE_USERID =
18       "SELECT user_userid "
19       + "FROM   users "
20       + "WHERE  user_id= ?  ";
21   
22   
23   
24     public static String retrieveUserId(long userId)
25        throws InstantbankException, SQLException {
26       Connection con = null;
27       PreparedStatement ps = null;
28       ResultSet rs = null;
29       DataAccess da = new DataAccess();
30       String userid = " ";
31   
32       try {
33         da.connect();
34         con = da.getConnection();
35         ps = con.prepareStatement(RETRIEVE_USERID);
36   
37         ps.setLong(1, userId);
38         rs = ps.executeQuery();
39         if(rs != null && rs.next()) {
40           userid = rs.getString(1);
41   
42         }
43       }
44       catch(Exception e) {
45         e.printStackTrace();
46         throw new InstantbankException(e, "812000", "Error searching for user USER ID");
47       }
48       finally {
49         SqlUtil.release(da.getConnection(), ps, rs);
50       }
51   
52       return userid;
53     }
54   
55   }
56