zoukankan      html  css  js  c++  java
  • JSP列表形式显示数据库中的数据 OracleCachedRowSet 实例

    现在数据库中有一张用户表,希望用户在jsp页面中输入用户名和密码以及 用户类型,在servlet中插入数据库后,在另一个jsp页面中把数据库中所有的用户名和类型都以列表的形式列出来    可以用OracleCachedRowSet实现了ResultSet中的所有方法The oracle.jdbc.rowset.OracleCachedRowSet class is the Oracle implementation of CachedRowSet

    servlet代码为:

    import oracle.jdbc.rowset.OracleCachedRowSet;

    PreparedStatement pUpd = con.prepareStatement("insert into myuser(username,password,user_type) values (?,?,?)" );
    pUpd.setString(1,userName);
    pUpd.setString(2,password);
    int ty=Integer.parseInt(type);
    pUpd.setInt(3,ty);
    int numRows = pUpd.executeUpdate();
    out.print("成功插入"+numRows+"行<br>");
    out.print("从数据库中读取您的注册信息为: <br>");
    pUpd = con.prepareStatement("select username,user_type from myuser " );
    rs = pUpd.executeQuery(); 
       OracleCachedRowSet ors = new OracleCachedRowSet();
    //将ResultSet中的数据封装到RowSet中
       ors.populate(rs);
      request.setAttribute("empRS",ors );

      RequestDispatcher rd;
          rd = getServletContext().getRequestDispatcher("/showResult.jsp");
          rd.forward(request,response); 

    显示用户名和类型都以列表的形式的读取数据jsp为:showResult.jsp

         


    <%@ page language="java" import="java.util.*,javax.sql.*,oracle.jdbc.rowset.OracleCachedRowSet" pageEncoding="utf-8"%>

     <body>
      <%
      OracleCachedRowSet empRS =(OracleCachedRowSet)request.getAttribute("empRS");
      
      %>

    <table  cellspacing="0" width=”90%”>
        <tr>  <td>用户名</td> <td>类型</td>  </tr>
    <%
      if (empRS != null) 
      while (empRS.next() ) 
      {
    %>
      <tr>  
        <td><%= empRS.getString("userName")%></td> 
        <td><%= empRS.getString("user_type")%></td>  
      </tr>
    <%
      }// end while
    %>
    </table>
      </body>


  • 相关阅读:
    bzoj3427:[POI2013]BAJ-Bytecomputer
    bzoj3417:[POI2013]MOR-Tales of seafaring
    bzoj1100:[POI2007]对称轴osi
    bzoj3295:[CQOI2011]动态逆序对
    bzoj2286:[SDOI2011]消耗战
    CF1110F Nearest Leaf
    CF1110E Magic Stones
    CF1110D Jongmah
    matlab基础向9:动画
    CF1102D-Balanced Ternary String-(贪心)
  • 原文地址:https://www.cnblogs.com/unflynaomi/p/4476855.html
Copyright © 2011-2022 走看看