Display data Oraclecachedrowset instances in a database as a JSP list

Source: Internet
Author: User

Now there is a user table in the database, you want the user to enter the user name and password and user type in the JSP page, after inserting the database in the servlet, in another JSP page, all the user names and types in the database are listed in the form of a list can be used Oraclecachedrowset implements all the methods in resultset, the oracle.jdbc.rowset. Oraclecachedrowset Class is the Oracle implementation of CachedRowSet

The servlet code is:

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 ("Successfully insert" +numrows+ "line <br>");
Out.print ("read your registration information from the database: <br>");
PUPD = Con.preparestatement ("Select Username,user_type from MyUser");
rs = Pupd.executequery ();
oraclecachedrowset ors = new Oraclecachedrowset ();
//package data in ResultSet into rowset
Ors.populate (RS);
Request.setattribute ("Emprs", ors);
RequestDispatcher Rd;
RD = Getservletcontext (). Getrequestdispatcher ("/showresult.jsp");
Rd.forward (Request,response);

The display user name and type are read in the form of a list of data jsps: 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> User name </td> <td> type </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>


Display data Oraclecachedrowset instances in a database as a JSP list

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.