Code with Finding: |
class SocialNetworkDatabaseBoards {
/**
* Determine whether the board exists.
* The return arg is null if there was an exc.
*/
public static Boolean boardExists(Connection conn, String boardName) {
String getBoard = "SELECT * FROM main.boards WHERE bname = ?";
PreparedStatement pstmt = null;
ResultSet boardResult = null;
Boolean boardExists = null; //null if there is an error.
try {
pstmt = conn.prepareStatement(getBoard);
pstmt.setString(1, boardName);
boardResult = pstmt.executeQuery();
boardExists = new Boolean(boardResult.next());
}
catch (SQLException e) {
e.printStackTrace();
}
finally {
DBManager.closePreparedStatement(pstmt);
DBManager.closeResultSet(boardResult);
}
return boardExists;
}
}
|