/** * Determine whether or a not a User with the supplied researcherID exists * * @param username The researcherID to test * @return true if the user exists, false if not * @throws SQLException if a database error was encountered */ public static boolean userExists(int researcherID) throws SQLException { boolean returnVal = false; // Get our connection to the database. Connection conn = DBConnectionManager.getConnection("yrc"); PreparedStatement stmt = null; ResultSet rs = null; try { stmt = conn.prepareStatement("SELECT researcherID FROM tblUsers WHERE researcherID = ?"); stmt.setInt(1, researcherID); rs = stmt.executeQuery(); // No rows returned. if (!rs.next()) { returnVal = false; } else { returnVal = true; } rs.close(); rs = null; stmt.close(); stmt = null; conn.close(); conn = null; } finally { // Always make sure result sets and statements are closed, // and the connection is returned to the pool if (rs != null) { try { rs.close(); } catch (SQLException e) {; } rs = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException e) {; } stmt = null; } if (conn != null) { try { conn.close(); } catch (SQLException e) {; } conn = null; } } return returnVal; }