java中如何对ResultSet返回的2D数组进行算术运算
我在java中有一个方法,它给出了一个包含各种列的表。其中一列为beam_current,其值在220之前为实型Now I want to display only those rows of the table where beam_current values are closest to 10,20,30..till 220.
为了做到这一点,我必须取一个变量并将其赋值为10,然后用beam_当前值减去它,我得到的最小值应该显示在表中。必须在while(rs.next)中运行for循环,例如
while(rs.next)
{
for(f=10;f<=220;f+10)`**//f+10 how to do in for?**`
{
variable=rs.getInt(2)`**//beam_current is second column**`
f-=variable;
code for least value of f`**//(how to code for it???)**`
}
}
但是我不知道如何为while的这个内部循环编写代码来检索所需的输出
我检索表的代码是
public String[][] ref_Details() {
int i = 0;
String a[][] = new String[47][11];
try {
con = getConnection();
stmt = con.createStatement();
String sql = " select b.LOGTIME, b.beam_current, b.beam_energy,case when a.st1_vs1_bag1_onoff=0 then c.st1_vs1_bag1_rb ELSE 0 END as st1_vs1_bag1_rb ,CASE when a.st1_vs1_bag2_onoff=0 then c.st1_vs1_bag2_rb else '0' END as st1_vs1_bag2_rb ,CASE when a.st1_vs1_bag3_onoff=0 then c.st1_vs1_bag3_rb else '0' END as st1_vs1_bag3_rb ,CASE when a.st1_vs1_bag4_onoff=0 then c.st1_vs1_bag4_rb else '0' END as st1_vs1_bag4_rb ,CASE when a.st1_vs1_bag5_onoff=0 then c.st1_vs1_bag5_rb else '0' END as st1_vs1_bag5_rb ,CASE when a.st1_vs1_bag6_onoff=0 then c.st1_vs1_bag6_rb else '0' END as st1_vs1_bag6_rb , CASE when a.st1_vs1_bag7_onoff=0 then c.st1_vs1_bag7_rb else '0' END as st1_vs1_bag7_rb ,CASE when a.st1_vs1_bag8_onoff=0 then c.st1_vs1_bag8_rb else '0' END as st1_vs1_bag8_rb from INDUS2_BDS.dbo.DCCT b INNER JOIN (main_vacuum_analog c inner join main_vacuum_status a on c.logtime=a.logtime) ON a.LOGTIME = b.LOGTIME and ( 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 '2014-10-10 07:17:00' and '2014-10-10 08:46:00'";
stmt.executeQuery(sql);
rs = stmt.getResultSet();
while (rs.next())
{
for (int j = 0; j < 11; j++) {
a[i][j] = rs.getString(j + 1);
}
i++;
}
} catch (Exception e) {
System.out.println("\nException " + e);
} finally {
closeConnection(stmt, rs, con);
}
return a;
}
现在我只想显示那些最接近10,20,30的行。。到220
共 (0) 个答案