To display number of rows counted along with data from database in tabular format

835 Views Asked by At

I want to retrieve two columns from database namely system_name and arrival_time and display these in tabular format. Now along with these two columns, I want to display a third column which will represent the number of times system_name appears in the table.

I'm using sql server 2012 and for display I use JSP AND JSTL.

I tried to write code for displaying two columns, but the output shows only the last data entries. The java code is:

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 code is:

< 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

There are 0 best solutions below