Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 将表中的数据动态检索到jsp中_Oracle_Jsp_Jdbc - Fatal编程技术网

Oracle 将表中的数据动态检索到jsp中

Oracle 将表中的数据动态检索到jsp中,oracle,jsp,jdbc,Oracle,Jsp,Jdbc,我有下面的代码从Oracle表中检索数据。这很好用 <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@include file="DBCon.jsp" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF

我有下面的代码从Oracle表中检索数据。这很好用

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="DBCon.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body><table>
        <%
        String a=request.getParameter("type").trim();
        String b=request.getParameter("user").trim();
        String c=request.getParameter("from").trim();
        String d=request.getParameter("to").trim();
        ResultSetMetaData rsmd;
        String st="SELECT type, Hari, Rakesh, Total FROM (select (type),  max( decode( SPECIALIST, 'Hari', cnt, null ) ) Hari,  max( decode( SPECIALIST, 'Rakesh', cnt, null ) ) Rakesh,  Sum(cnt) total  from ( select (type),specialist, sum(update_count) cnt  from scope1 where (RECVD_DATE >='"+c+"' and RECVD_DATE <='"+d+"')  group by (type),specialist ) q  group by (type)  Union Select 'Total' as type, Sum(Hari) Hari,Sum(Rakesh) Rakesh,Sum(total) Total from (  select (type),  max( decode( SPECIALIST, 'Hari', cnt, null ) ) Hari,  max( decode( SPECIALIST, 'Rakesh', cnt, null ) ) Rakesh,  Sum(cnt) total  from ( select (type),specialist, sum(update_count) cnt  from scope1 where (RECVD_DATE >='"+c+"' and RECVD_DATE <='"+d+"')  group by (type),specialist ) q  group by (type)  )a) b Order by Total";        
try{%>
        <tr><b><%=b%></b></tr><%
            //String sql=(st);
            //out.print(sql);
            ps1=con.prepareStatement(st);
            rs1=ps1.executeQuery();
            rsmd=rs1.getMetaData();
            int cou=rsmd.getColumnCount();
            for(int i=1;i<cou;i++){
            %>
        <td><%=rsmd.getColumnName(i)%>
        <%
                   }
            %>
        <td>Total</td>
        <%
            while(rs1.next())
            {
            %>

            <tr><td><b><%=rs1.getString(1)%></b></td><td><%=rs1.getString(2)%></td><td><%=rs1.getString(3)%></td><td><%=rs1.getString(4)%> </td></tr>
            <%
            }
        }
        catch(Exception e)
        {
            out.println(e);
}
%>
   </table> </body>
</html>

JSP页面
='“+c+”'和记录日期='“+c+”'和记录日期

但是我永远不会这样做。JSP不应该使用scriptlet。他们不应该执行数据库查询。他们唯一的工作应该是使用存储在请求属性中的对象生成HTML标记

SQL查询应该位于首选MVC框架的servlet或操作中。这个servlet将获取数据,将其存储在
列表中,将该列表放入请求属性中,然后转发给JSP

然后JSP将使用JSTL和JSPEL(以及其他自定义标记,如果需要的话),以显示这个
列表

<tr><td><b><%=rs1.getString(1)%></b></td><td><%=rs1.getString(2)%></td><td><%=rs1.getString(3)%></td><td><%=rs1.getString(4)%> </td></tr>
SELECT type, Hari, Rakesh, Total FROM (select (type),  max( decode( SPECIALIST, 'Hari', cnt, null ) ) Hari,  max( decode( SPECIALIST, 'Rakesh', cnt, null ) ) Rakesh,  Sum(cnt) total  from ( select (type),specialist, sum(update_count) cnt  from scope1 where (RECVD_DATE >='"+c+"' and RECVD_DATE <='"+d+"')  group by (type),specialist ) q  group by (type)  Union Select 'Total' as type, Sum(Hari) Hari,Sum(Rakesh) Rakesh,Sum(total) Total from (  select (type),  max( decode( SPECIALIST, 'Hari', cnt, null ) ) Hari,  max( decode( SPECIALIST, 'Rakesh', cnt, null ) ) Rakesh,  Sum(cnt) total  from ( select (type),specialist, sum(update_count) cnt  from scope1 where (RECVD_DATE >='"+c+"' and RECVD_DATE <='"+d+"')  group by (type),specialist ) q  group by (type)  )a) b Order by Total
<%=rs1.getString(i)%>
<%
for (int i = 1; i < 5; i++) {
%>

<td><%= rs1.getString(i) %></td>

<%
}
%>