JSTL代码转换为Java类,或者我如何在Separate类中实现它



我有下面的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); 
                }
            }

创建一个简单的JDBC类,它可以获得DATEs和TITLE的列表,然后将其作为属性发送到JSP,使用JSTL代码来编写它。

相关内容

  • 没有找到相关文章

最新更新