Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public User getUserById (int id) {
- User user = null;
- try {
- Connection conn = ConnectionManager.getConnection();
- String query = "SELECT userName, userPassword FROM User WHERE id = ?";
- PreparedStatement pstmt = conn.prepareStatement(query);
- pstmt.setInt(1, id);
- ResultSet rset = pstmt.executeQuery();
- if (rset.next()) {
- String userName = rset.getString(1);
- String userPassword = rset.getString(2);
- user = new User (userName, userPassword);
- }
- rset.close();
- pstmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return user;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement