If you use the JDBC 2.0 api you can scroll through a resultset, go directly to a row 
etc.

gerardo

Esteban Felipe wrote:

> Hi all. Let me introduce you my case. I'm developing a workers control system
> with pure java servlets. I'm using Visual Age for java, IBM Http server and IBM
> Websphere application server. I'm curretly working in  the administration
> module. The idea is to provide a service indenpendent of the database model.
> What i'm trying to do is a servlet that query the DB structure and render in a
> web page the neccesary fields for input a new record, and at the same time
> displays all availables records in the table with options to deleto or modify
> the record. Here is the code i wrote:
>
> package com.ibm.pss.servlets;
> import java.io.*;
> import java.sql.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> public class TableMgrServlet extends ServletConnection {
> public TableMgrServlet() {
>      super();
>      setDbName("MODELO");
>      setDriverName("COM.ibm.db2.jdbc.app.DB2Driver");
>      setPoolName("MyConnectionPool");
>
> }
> public void doGet(javax.servlet.http.HttpServletRequest req,
> javax.servlet.http.HttpServletResponse res) throws
> javax.servlet.ServletException, java.io.IOException {
>      res.setContentType("text/html");
>      PrintWriter out = res.getWriter();
>      out.println("<HTML><HEAD><TITLE>AJFDIASJDKASJD</TITLE></HEAD><BODY
> BGCOLOR=\"#003333\" LINK=\"#FF3300\" VLINK=\"#FF6600\" TEXT=\"#FFFFFF\"
> TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0><CENTER>");
>      HttpSession session = req.getSession(false);
>
> setUserName((String)session.getValue("com.ibm.pss.servlets.LoginServlet.UserName"));
>
> 
>setUserPassword((String)session.getValue("com.ibm.pss.servlets.LoginServlet.UserPassword"));
>      connect();
>      try{
>           TableMetaDataMgr TMetaData = new
> TableMetaDataMgr(getConnection(),getParameter(req,"tabla"),out);
>           releaseConnection();
>      }catch(Exception e){ out.println(e); }
>      out.println("</CENTER></BODY></HTML>");
>      out.close();
>
> }
>
> package com.ibm.pss.servlets;
>
> import java.io.*;
> import java.sql.*;
> import java.util.*;
> public class TableMetaDataMgr {
>      private Connection conn = null;
>      private String TableName = null;
>      private PrintWriter out;
>      private DatabaseMetaData MyMetaData = null;
> public TableMetaDataMgr(Connection con, String TableName,PrintWriter out) {
>      super();
>      this.conn = con;
>      this.TableName = TableName;
>      this.out= out;
>      try{
>           MyMetaData = conn.getMetaData();
>           this.columnsExtract();
>      }catch(Exception e) { out.println(e);}
> }
> private synchronized void columnsExtract() {
>      ResultSet rs2 = null;
>      Statement stmt = null;
>      ResultSetMetaData rsMetaData = null;
>      try{
>           stmt = conn.createStatement();
>           rs2= stmt.executeQuery("SELECT * FROM DB2ADMIN."+TableName);
>           rsMetaData = rs2.getMetaData();
>           out.println("<CENTER><FORM
> ACTION=\"http://seniat1/servlet/AddRecordServlet\" METHOD=\"GET\">");
>           out.println("<TABLE BORDER=\"0\">");
>           int i;
>           for(i=0;i<rsMetaData.getColumnCount();i++){
>                out.println("<TR>");
>                out.println("<TD>"+rsMetaData.getColumnName(i+1)+"</TD>");
>                out.println("<TD><INPUT TYPE=\"TEXT\"
> NAME=\""+rsMetaData.getColumnName(i+1)+"\"></td>");
>           }
>           out.println("</TABLE>");
>           out.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"AGREGAR\">");
>           out.println("<INPUT TYPE=\"RESET\"
> VALUE=\"CANCELAR\"></FORM></CENTER>");
>           out.println("<br><br>");
>           out.println("<CENTER><FORM
> ACTION=\"http://seniat1/servlet/UpdateDeleteRecordServlet\" METHOD=\"GET\">");
>           out.println("<TABLE BORDER=\"1\" cellpadding=\"1\"
> cellspacing=\"1\">");
>           out.println("<THEAD><H1><CENTER>"+TableName+"</CENTER></H1></THEAD>");
>           out.println("<TR>");
>           for(i=0;i<rsMetaData.getColumnCount();i++){
>                out.println("<TH>"+rsMetaData.getColumnName(i+1)+"</TH>");
>           }
>           out.println("</TR>");
>           while(rs2.next()){
>                out.println("<TR>");
>                for(i=0;i<rsMetaData.getColumnCount();i++){
>                     out.println("<TD>"+rs2.getString(i+1)+"</TD>");
>                }
>                out.println("<TD><INPUT TYPE=\"SUBMIT\"
> VALUE=\"MODIFICAR\"><BR><INPUT TYPE=\"SUBMIT\" VALUE=\"ELIMINAR  \"></TD>");
>                out.println("</TR>");
>           }
>           out.println("</TABLE></FORM></CENTER>");
>      }catch(Exception e){ out.println(e); }
>
> }
> }
>
> The super class ServletConnection is for the Connection pool managment, so it
> doesn't care. The problem  occurs when the table contents more than 100 records.
>  When this happend the web page render wrong!. I don't konw much about html but
> i guess it must be a HTML or browser problem.
>
> The only solution that i thought was to divide the ResultSet in short pieces of
> about 15 records and provide a "next" link, but the ResultSet interface doesn't
> provide methods to set the cursor. I'd need this for record count and for allow
> the user to go foward and backward as needed. Any idea?
>
> Esteban Felipe
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
begin:vcard
n:Macari;Gerardo
tel;work:Corel Europa House Hartcourt st, Dublin (Ireland)
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:[EMAIL PROTECTED]
fn:Gerardo Macari
end:vcard

Reply via email to