I think that the problem with this class is that setColumnNames and 
setData aren't really setting attributes.  I suppose I should make 
instance attributes like "header" and "data"?

(luckily we're moving into JSP soon, but, still...)

also, is there a problem with passing ResultSet around to different 
objects?  I read that there's a problem with that.


package a00720398.html;

//adapted from oreilly sample in ch 16
//      Java Servlet Programming, Second Edition
//         http://oreilly.com/catalog/9780596000400/


import java.sql.*;
import org.apache.ecs.html.*;


public class ResultSetTable extends Table {

    private static final boolean isPretty = true;
    private ResultSet rst = null;
    ResultSetMetaData rsmd = null;

    public ResultSetTable() {
    }

    public ResultSetTable(ResultSet rst) throws SQLException {
        this.rst = rst;
        rsmd = rst.getMetaData();
        setBorder(1);
        setColumnNames();
        setData();
    }
    
    public void setResultSet(ResultSet rst) throws SQLException {
        this.rst = rst;
        rsmd = rst.getMetaData();
    }
  
    private void setColumnNames() throws SQLException {
        int colCount = rsmd.getColumnCount();
        TR tr = new TR();
        tr.setPrettyPrint(isPretty);

        A a = new A();
        a.setPrettyPrint(isPretty);
        a.setHref("/Assignment?crud=D&row=0");
        //<http://www.google.ca/search?q=doget
+url&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-
US:unofficial&client=firefox-a
        a.addElement("delete");

        TH colZero = new TH();
        colZero.setPrettyPrint(isPretty);
        colZero.addElement(a);
        tr.addElement(colZero);

        for (int i = 1; i <= colCount; i++) {
            TH th = new TH();
            th.setPrettyPrint(isPretty);
            th.addElement(rsmd.getColumnLabel(i));
            tr.addElement(th);
        }
        addElement(tr);
    }

    private void setData() throws SQLException {
        int colCount = rsmd.getColumnCount();
        TR tr = new TR();

        //rst.beforeFirst();
        while (rst.next()) {
            tr = new TR();
            tr.setPrettyPrint(isPretty);
            for (int i = 1; i <= colCount; i++) {
                TH th = new TH();
                th.setPrettyPrint(isPretty);
                th.addElement(rst.getString(i));
                tr.addElement(th);
            }
            addElement(tr);
        }
    }
}



thanks,

Thufir


---------------------------------------------------------------------
To unsubscribe, e-mail: ecs-user-unsubscr...@jakarta.apache.org
For additional commands, e-mail: ecs-user-h...@jakarta.apache.org

Reply via email to