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