Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_jsp thread: Returning recordsets from a bean.


Message #1 by "Nick" <nickm@s...> on Wed, 20 Jun 2001 23:49:08 -0500
Hi:

I have been working on the use of beans in JSP applications. I have no
problems with using beans to insert data into a database and doing select
where I return one record. But when it comes to returning recordsets I have
not been able to do it successfully but in a clunky way. In the code below I
can get a ROW of data if I make multiple calls to getName method of my bean
and specify the column number in the method arguement but there has to be a
way I can return a row and display it in my JSP with a single method call
and query. Any help would be appreciated.

JSP CODE to return records from a bean (stats):

<%
Vector sv = stats.getName(2);
Vector v = stats.getName(3);
for(int i = 1; i < v.size(); ++i) {
%>

<br><%=v.elementAt(i)%>: <%=sv.elementAt(i)%>

<%
}
%>

The BEAN code:

 public Vector getName(int col) throws Exception
    {

            DBPool pool = DBPool.getPool("SuperPlay");
            Connection conn = pool.getConnection();
            Statement stmt = conn.createStatement();
            rs = stmt.executeQuery("Select * FROM tbl_Teams");
            Vector list = new Vector();
            while(rs.next()) {
                list.addElement(rs.getString(col));
            }
             return list;


  Return to Index