@Override public Role findById(String key) throws SQLException { Role retval = null; ResultSet rs = null; PreparedStatement pstmt = null; try { con = new DBConnection(); if (con.connect()) { String sql = "select * from role where rolename=?"; pstmt = con.getConnection().prepareStatement(sql); pstmt.setString(1, key); rs = con.customQuery(pstmt); while (rs.next()) { Role role = new Role(); role.setRolename(rs.getString("rolename")); role.setDescription(rs.getString("description")); retval = role; } } } catch (ClassNotFoundException ex) { logger.log(Priority.ERROR, ex.toString()); } catch (SQLException ex) { throw ex; } finally { con.disconnect(); } return retval; }
@Override public List<Role> getAll() throws SQLException { List<Role> retval = new ArrayList<Role>(); ResultSet rs = null; try { con = new DBConnection(); if (con.connect()) { cstmt = (CallableStatement) con.getConnection().prepareCall("{call sp_sel_role()}"); rs = con.customQuery(cstmt); while (rs.next()) { Role role = new Role(); role.setRolename(rs.getString("rolename")); role.setDescription(rs.getString("description")); retval.add(role); } } } catch (ClassNotFoundException ex) { logger.log(Priority.ERROR, ex.toString()); } catch (SQLException ex) { throw ex; } finally { con.disconnect(); } return retval; }