public SlaParam getSlaParamById(int slaParamId) { SlaParam slaParam = new SlaParam(); try { PreparedStatement preparedStatement = connection.prepareStatement("select * from casvid_slaparameters where slaparam_id =?"); preparedStatement.setInt(1, slaParamId); ResultSet rs = preparedStatement.executeQuery(); if (rs.next()) { slaParam.setSlaParamId(rs.getInt("slaparam_id")); slaParam.setSlaParamName(rs.getString("slaparam_name")); slaParam.setSlaParamUnit(rs.getString("slaparam_unit")); slaParam.setSlaParamDesc(rs.getString("slaparam_description")); } } catch (SQLException e) { e.printStackTrace(); } return slaParam; }
public List<SlaParam> getAllSlaParams(String search) { List<SlaParam> slaParams = new ArrayList<SlaParam>(); try { Statement statement = connection.createStatement(); String strSql = "select * from casvid_slaparameters"; if (!search.isEmpty()) { strSql = strSql + " where slaparam_name like'%" + search + "%'"; } ResultSet rs = statement.executeQuery(strSql); while (rs.next()) { SlaParam slaParam = new SlaParam(); slaParam.setSlaParamId(rs.getInt("slaparam_id")); slaParam.setSlaParamName(rs.getString("slaparam_name")); slaParam.setSlaParamUnit(rs.getString("slaparam_unit")); slaParam.setSlaParamDesc(rs.getString("slaparam_description")); slaParams.add(slaParam); } } catch (SQLException e) { e.printStackTrace(); } return slaParams; }