以表格格式显示计算的行数以及数据库中的数据

时间:2014-12-09 07:19:39

标签: java sql-server list linkedhashmap rowcount

我想从数据库中检索两列system_namearrival_time,并以表格格式显示这些列。现在连同这两列,我想显示第三列,它表示system_name在表格中出现的次数。

我正在使用sql server 2012,为了显示我使用JSP和JSTL。

我尝试编写用于显示两列的代码,但输出仅显示最后的数据条目。 java代码是:

public LinkedHashMap < String, String > alarm_Detail()

{
  try {
    con = getConnection();

    stmt = con.createStatement();
    String sql = "select distinct * from i2alarmlog where Ack_status=0 AND Direction='CAME' ";

    stmt.executeQuery(sql);
    rs = stmt.getResultSet();

    while (rs.next()) {

      Map1.put(rs.getString("system_name"), rs.getString("arrival_time"));
    }



  } catch (Exception e) {
    System.out.println("\nException i(String code):" + e);
  } finally {
    closeConnection(stmt, rs, con);
  }

  return Map1;
}

Jsp代码是:

< body >
  < jsp: useBean id = "ab"
class = "alarm.Alarm_Bean" >

  < /jsp:useBean>
<table width = "300px" border = "1" cellspacing="2">
<tr>
<th>system_name</th >
  < th > arrival_time < /th>
</tr >
  < c: forEach
var = "country"
items = "${ab.alarm_Detail()}" >
  < tr >
  < td > $ {
    country.key
  } < /td>
   <td> ${country.value} </td >
  < /tr>  
</c: forEach >

  < /table> 


</body >

0 个答案:

没有答案