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>


  • 相关阅读:
    在windows下如何批量转换pvr,ccz为png或jpg
    cocos2d-x 中的 CC_SYNTHESIZE 自动生成 get 和 set 方法
    制作《Stick Hero》游戏相关代码
    触摸事件的setSwallowTouches()方法
    随机生成数(C++,rand()函数)
    随机生成数
    cocos2d-x 设置屏幕方向 横屏 || 竖屏
    Joystick 摇杆控件
    兔斯基 经典语录
    Cocos2d-x 3.2 EventDispatcher事件分发机制
  • 原文地址:https://www.cnblogs.com/unflynaomi/p/4476855.html
Copyright © 2011-2022 走看看