如何在表(jsp)中显示Mysql数据库数据

时间:2019-05-13 03:34:28

标签: java mysql jsp netbeans

我想使用JSP在网页中显示数据库结果。

我已经按照各种教程进行了学习,似乎代码本身并没有错,但是当我运行Java WebApp时,该网页显示了一个只有标题的空白表。

我想知道我的代码是否有问题,主要是我是否在表格中正确显示了结果集的结果

我已经在Java类上运行了Java部分,并且数据库连接工作正常,如果我输出结果集,它将显示数据库中的数据

<table border="2" align="center" > 

 <tr>
 <th>NIT Planta</th>
 <th>Direccion</th>
 <th>Proceso</th>
 </tr>

 <%
    Connection cnx=null;
    Statement sta=null;
    ResultSet rs=null;
    try
    {
     Class.forName("com.mysql.jdbc.Driver");
     cnx=DriverManager.getConnection("jdbc:mysql://localhost:3306/empresamoda","root","123456");

     sta=cnx.createStatement();
     rs=sta.executeQuery("SELECT Pdp.NIT_Planta,Pdp.DireccionPlanta,Pdpro.DescripcionProceso "
           + "                FROM Planta_de_produccion Pdp INNER JOIN Proceso_de_Produccion Pdpro "
           + "                ON Pdp.ID_Planta=Pdpro.ID_Planta");
    while(rs.next()){
       %>
       <tr>
           <td><%=rs.getString(1)%></td>
           <td><%=rs.getString(2)%></td>
           <td><%=rs.getString(3)%></td>
       </tr>


       <%
    }
    sta.close();
    rs.close();
    cnx.close();
    }
    catch(Exception e){

     }
 %>

</table>

我希望看到结果集出现在网页中的表上,而不仅仅是空白表。

0 个答案:

没有答案
相关问题