0

我有以下 JSTL 代码,

<sql:setDataSource  dataSource="jdbc/xxx"/>
   <sql:query var="ab" scope="application"  maxRows="100">
   select Distinct DATE(timestamp) as DATE from tableA ORDER BY DATE DESC LIMIT 100;
   </sql:query>  
   <c:forEach var="row" items="${ab.rows}">
   <h1><c:out value="${row.DATE}"/></h1>
   <sql:query var="abc" scope="application"  maxRows="100">
   Select title from tableA Where DATE(timestamp) = "<c:out value="${row.DATE}"/>";
   </sql:query>                          
   <c:forEach var="row" items="${abc.rows}">
   <c:out value="${row.title}"/><br><br>
   </c:forEach>
   </c:forEach>

如何实现与 java 类相同的要求。这是我的要求,此 JSTL 代码满足基于日期显示数据

这是我正在尝试的类代码,

HashMap<ArrayList<Date>, ArrayList<String>> TitleList = new HashMap<ArrayList<Date>,ArrayList<String>>();
        ArrayList<Date> DateList = new ArrayList<Date>();
        ArrayList<String> Title = new ArrayList<String>();
        ArrayList<Date> DateListinner = new ArrayList<Date>();
        List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
        String sqld = "Select Distinct DATE(timestamp) as DATE from TABLE A ORDER BY DATE DESC LIMIT 100";
        ResultSet rsd = null;
        try {
            rsd = stmt1.executeQuery(sqld);
        } catch (SQLException ex) {
            Logger.getLogger(sortxx.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while (rsd.next()) {
                System.out.println("Testing");
                Date Date = rsd.getDate("Date");
                System.out.println(Date);
                DateList.add(Date);
                String sql = "Select title,DATE(timestamp) as DATE from TABLEA Where DATE(timestamp) = '" + Date + "'";
                //     System.out.println(sql);
                ResultSet rs = stmt.executeQuery(sql);
                ResultSetMetaData metaData = rs.getMetaData();
                int columnCount = metaData.getColumnCount();
                System.out.println(columnCount);
                while (rs.next()) {
                    String title = rs.getString("title");
                    Title.add(title);
                    //     System.out.println("Testing inside");
                    System.out.println(rs.getString("title"));           
                    DateListinner.add(rs.getDate("DATE"));
                    Map<String, Object> columns = new LinkedHashMap<String, Object>();
                    for (int i = 1; i <= columnCount; i++) {
                        columns.put(metaData.getColumnLabel(i), rs.getObject(i));
                    }
                    rows.add(columns);
                    TitleList.put(DateList,Title); 
                }
            }
4

1 回答 1

0

创建简单的JDBC类,获取 DATE 和 TITLE 列表,然后将其作为属性发送到 JSP,使用您的 JSTL 代码将其写出。

于 2012-07-27T06:05:01.620 回答