我有一个方法,通过它我可以检索对应于列名的一些行,即beam_current.Now对应于beam_current我想只显示一行。但是现在有时会检索多行,对应于beam_current值
我显示的输出是 -
这里对应于beam_current 50,有两行以cornsilk颜色显示。现在我希望两行中的任何一行都显示出来。如何做到这一点。
我在java类中的代码是 -
public List < Comaprision > refarray_vac1(String date) throws SQLException, ParseException {
st_jsp.clear();
List < Double > slist_user = new ArrayList < Double > (map1.keySet());
String s_user = StringUtils.join(slist_user, ',');
try {
con = getConnection();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
String vs1 = "select b.logtime, b.beam_current, b.beam_energy,case " +
"when a.st2_vs2_bag1_onoff=0 then c.st2_vs2_bag1_rb ELSE 0 END as st2_vs2_bag1_rb," +
"CASE when a.st2_vs2_bag2_onoff=0 then c.st2_vs2_bag2_rb else '0' END as st2_vs2_bag2_rb," +
"CASE when a.st2_vs2_bag3_onoff=0 then c.st2_vs2_bag3_rb else '0' END as st2_vs2_bag3_rb," +
"CASE when a.st2_vs2_bag4_onoff=0 then c.st2_vs2_bag4_rb else '0' END as st2_vs2_bag4_rb," +
"CASE when a.st2_vs2_bag5_onoff=0 then c.st2_vs2_bag5_rb else '0' END as st2_vs2_bag5_rb," +
"CASE when a.st2_vs2_bag6_onoff=0 then c.st2_vs2_bag6_rb else '0' END as st2_vs2_bag6_rb," +
"CASE when a.st2_vs2_bag7_onoff=0 then c.st2_vs2_bag7_rb else '0' END as st2_vs2_bag7_rb," +
"CASE when a.st2_vs2_bag8_onoff=0 then c.st2_vs2_bag8_rb else '0' END as st2_vs2_bag8_rb," +
"CASE when a.st2_vs2_bag9_onoff=0 then c.st2_vs2_bag9_rb else '0' END as st2_vs2_bag9_rb " +
"from INDUS2_BDS.dbo.DCCT b INNER JOIN(INDUS2_VACUUM.dbo.main_vacuum_analog c inner join INDUS2_VACUUM.dbo.main_vacuum_status a on c.logtime=a.logtime)" +
"ON a.LOGTIME = b.LOGTIME and (b.beam_current like '%9.96' or b.beam_current like '%9.97' or b.beam_current like '%9.98' or b.beam_current like '%9.99' or b.beam_current like '%0' or b.beam_current like '%_0.01' or b.beam_current like '%_0.02' or b.beam_current like '%_0.03' or b.beam_current like '%_0.04' or b.beam_current like '%_0.05' or b.beam_current like '%_0.06')" +
"and b.logtime between '" + date + " 00:00:00' and '" + date + " 23:59:59' and b.beam_current in(" + s_user + ") and ( b.beam_energy between '550' and '551' ) order by b.beam_current ";
System.out.println("vs1: " + vs1);
stmt.executeQuery(vs1);
rs = stmt.getResultSet();
while (rs.next()) {
Comaprision ref = new Comaprision();
ref.setLogtime(rs.getString(1));
ref.setBeam_current(rs.getString(2));
ref.setBeam_energy(rs.getString(3));
ref.setSt2_vs2_bag1_rb(rs.getString(4));
ref.setSt2_vs2_bag2_rb(rs.getString(5));
ref.setSt2_vs2_bag3_rb(rs.getString(6));
ref.setSt2_vs2_bag4_rb(rs.getString(7));
ref.setSt2_vs2_bag5_rb(rs.getString(8));
ref.setSt2_vs2_bag6_rb(rs.getString(9));
ref.setSt2_vs2_bag7_rb(rs.getString(10));
ref.setSt2_vs2_bag8_rb(rs.getString(11));
ref.setSt2_vs2_bag9_rb(rs.getString(12));
st_jsp.add(ref);
}
} catch (Exception e) {
System.out.println("\nException in refarray_vac1 " + e);
}
return st_jsp;
}
答案 0 :(得分:1)
看起来像是:
String previousBeam = null;
while (rs.next()) {
String currentBeam = rs.getString(2);
if (!currentBeam.equals(previousBeam)) {
previousBeam = currentBeam;
Comaprision ref = new Comaprision();
ref.setLogtime(rs.getString(1));
// ...
ref.setSt2_vs2_bag9_rb(rs.getString(12));
stJsp.add(ref);
}
}
答案 1 :(得分:1)
你可以使用一个hashset并向其中添加元素,并且只显示hashset中不包含的元素:
HashSet set = new HashSet<String>();
while(rs.next())
{
if(!set.add(rs.getString(2))) // 2 here corresponds to the index of beam_current
{
//you continue and do w/e
}
}