如何在一个 jsp 中使用多个 select 语句

How to use Multiple select statement in one jsp

我是 JSP 中的新手实际上我想在 JSP 页面中执行多个 Select 查询 Select 查询已执行但如果我尝试写第二个 select query it is not working giving me browser error connection refuse 只是我想知道我们如何在一个 jsp 中使用多个 select 语句这是我的下面的代码

<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>My First JSP Application in Net Beans</title>
    </head>
    <body>
        <h1>Hello World! This is my First JSP web Page in Netbeans</h1>

        <h3>Todays Policy Count</h3>

        <%java.sql.Connection con;
java.sql.Statement state;
java.sql.ResultSet rs;
//java.sql.PreparedStatement pst;

con=null;
state=null;
//pst=null;
rs=null;

try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databaseName=Testing_DB;user=Atul;password=Pass@123";
con=DriverManager.getConnection(url);
state=con.createStatement();
//String sql="SELECT * FROM first_test";
String sql="select distinct gp.product_name,Count(1) as counting from gt_policy gp inner join gt_user_doc_recon dr on gp.alternate_policy_no=dr.udr_pol_no where gp.erp_intg_status is null group by gp.product_name";
rs=state.executeQuery(sql);
%>
<table border="1" width="10%">
    <tr>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow"> product_name</font></font></th>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow">counting</font></font></th>
    </tr>
    <% 
    while(rs.next())
    {
    %>
    <tr>
         <font size="2">
        <td>
            <%
            String product_name=rs.getString("product_name");
            String counting=rs.getString("counting");



            out.println(product_name);
            %> 
             <font size="2">
        </td>
        <td>
            <font size="2">
            <%
            //out.println(name);    
            out.println(counting);
            }
           %>
           </font>
        </td>


    </tr>

</table>

<%
    }
catch (ClassNotFoundException e)
    {
      e.printStackTrace();
      System.exit(1);
    }
    catch (SQLException e)
    {
      e.printStackTrace();
      System.exit(2);
    }


%>
    </body>
</html>

这是我通过输出得到的答案

<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>My First JSP Application in Net Beans</title>
    </head>

        <h1>Hello World! This is my First JSP web Page in Netbeans</h1>



        <%java.sql.Connection con;
java.sql.Statement state,state1,state2,state3;
java.sql.ResultSet rs,rs1,rs2,rs3;

//java.sql.PreparedStatement pst;

con=null;
state=null;
//pst=null;
rs=null;
rs1=null;
state1=null;
rs2=null;
state2=null;
rs3=null;
state3=null;

try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databaseName=Testing_DB;user=Atul;password=Pass@123";
//String url="jdbc:sqlserver://HOST:1433;DatabaseName=Testing_DB";
//String url="jdbc:sqlserver://localhost;databaseName=Testing_DB;";
con=DriverManager.getConnection(url);
state=con.createStatement();
state1=con.createStatement();
state2=con.createStatement();
state3=con.createStatement();

String sql="";
rs=state.executeQuery(sql);

String sql1="";
rs1=state1.executeQuery(sql1);

//
String sql2="";
rs2=state2.executeQuery(sql2);
//
//
//
String sql3="";
rs3=state3.executeQuery(sql3);




%>

  <div style="float: left; width:12%;">
       <h5>Todays Policy Count</h5>

<table border="1" width="10%">
    <tr>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow"> product_name</font></font></th>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow">counting</font></font></th>

    </tr>
    <% 
    while(rs.next())
    {
    %>
    <tr>
         <font size="2">
        <td>
            <%
            String product_name=rs.getString("product_name");
            String counting=rs.getString("counting");





            out.println(product_name);
            %> 

        </td>
        <td>
            <font size="2">
            <%

            out.println(counting);
            }
           %>
           </font>
        </td>




    </tr>

</table>
           </div>


           <div style="float: left; width:12%;">
               <h5>SYNC REPORT</h5>
<table border="1" width="12%">
    <tr>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow"> PUS_SYNC_DATE</font></font></th>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow">STATUS</font></font></th>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow">COUNT</font></font></th>
    </tr>
    <% 
    while(rs1.next())
    {
    %>
    <tr>
        <td>
         <font size="2">

            <%
            String PUS_SYNC_DATE=rs1.getString("PUS_SYNC_DATE");
            String STATUS=rs1.getString("STATUS");
            String COUNT=rs1.getString("COUNT");





            out.println(PUS_SYNC_DATE);
            %> 
        </td>

        <td>
            <font size="2">
            <%
            //out.println(name);    
            out.println(STATUS);

           %>
           </font>
        </td>


        <td>
            <font size="2">
            <%
            //out.println(name);    
            out.println(COUNT);
            }
           %>
           </font>
        </td>



    </tr>

</table>
           </div>



           <div style="float: RIGHT; width:71%;">
               <h5>SYNC WITH ID REPORT</h5>
<table border="1" width="50%">
    <tr>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow"> PUS_SYNC_DATE</font></font></th>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow">PUS_UD_USER_ID</font></font></th>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow">PUS_SYNC_ERROR_DESC</font></font></th>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow">STATUS</font></font></th>
    </tr>
    <% 
    while(rs2.next())
    {
    %>
    <tr>
        <td>
         <font size="2">

            <%
            String PUS_SYNC_DATE=rs2.getString("PUS_SYNC_DATE");
            String PUS_UD_USER_ID=rs2.getString("PUS_UD_USER_ID");
            String PUS_SYNC_ERROR_DESC=rs2.getString("PUS_SYNC_ERROR_DESC");
            String STATUS=rs2.getString("STATUS");





            out.println(PUS_SYNC_DATE);
            %> 
        </td>

        <td>
            <font size="2">
            <%
            //out.println(name);    
            out.println(PUS_UD_USER_ID);

           %>
           </font>
        </td>


        <td>
            <font size="2">
            <%
            //out.println(name);    
            out.println(PUS_SYNC_ERROR_DESC);

           %>
           </font>
        </td>

        <td>
            <font size="2">
            <%
            //out.println(name);    
            out.println(STATUS);
            }

           %>
           </font>
        </td>



    </tr>

</table>
           </div>


            <div style="position:absolute;top:0; right:0;">
               <h5>POLICY ACCEPTED </h5>
<table border="1" width="50%">
    <tr>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow"> PRODUCT_NAME</font></font></th>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow">ACCEPTED ON</font></font></th>
        <th bgColor="Red"><font size="0.3"> <font color="Yellow">ALTERNATE_POLICY_NO</font></font></th>

    </tr>
    <% 
    while(rs3.next())
    {
    %>
    <tr>
        <td>
         <font size="2">

            <%
            String PRODUCT_NAME=rs3.getString("PRODUCT_NAME");
            String ACCEPTED_ON=rs3.getString("udr_date");
            String ALTERNATE_POLICY_NO=rs3.getString("ALTERNATE_POLICY_NO");






            out.println(PRODUCT_NAME);
            %> 
        </td>

        <td>
            <font size="2">
            <%
            //out.println(name);    
            out.println(ACCEPTED_ON);

           %>
           </font>
        </td>


        <td>
            <font size="2">
            <%
            //out.println(name);    
            out.println(ALTERNATE_POLICY_NO);
            }
           %>
           </font>
        </td>



    </tr>

</table>
           </div>



<%
    }
catch (ClassNotFoundException e)
    {
      e.printStackTrace();
      System.exit(1);
    }
    catch (SQLException e)
    {
      e.printStackTrace();
      System.exit(2);
    }


%>