Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 68544 invoked from network); 24 Dec 2004 04:06:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 24 Dec 2004 04:06:06 -0000 Received: (qmail 53927 invoked by uid 500); 24 Dec 2004 04:05:44 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 53204 invoked by uid 500); 24 Dec 2004 04:05:42 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 53106 invoked by uid 99); 24 Dec 2004 04:05:42 -0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=FORGED_RCVD_HELO,HTML_MESSAGE X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from ncr-static-120.237.247.61.touchtelindia.net (HELO win2003server.computerware.co.in) (61.247.237.120) by apache.org (qpsmtpd/0.28) with ESMTP; Thu, 23 Dec 2004 20:05:38 -0800 Subject: RE: Newbie question on Database and struts Date: Fri, 24 Dec 2004 09:35:34 +0530 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C4E96D.D1168E59" Message-ID: <2024453DA96BC0418B107F4923D8AEAF2029CF@win2003server.computerware.co.in> Content-class: urn:content-classes:message X-MS-Has-Attach: X-MS-TNEF-Correlator: X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 Thread-Topic: Newbie question on Database and struts Thread-Index: AcTpaJHy6CboR51JQ+WEKLrkOuzM1gABJu+w From: "Amit Gupta" To: "Tomcat Users List" Cc: X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N ------_=_NextPart_001_01C4E96D.D1168E59 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Following code fetch records from database table , populate them to = hastable and create vector of these hashtables . Then we pass this = vector to JSP through request attribute. Action class import org.apache.struts.action.*; import javax.servlet.http.*; import java.sql.*; import java.util.*; import org.apache.commons.beanutils.*; public class viewWsForkliftsAction extends = org.apache.struts.action.Action { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { HttpSession session=3Drequest.getSession(); if(session.getAttribute("username")!=3Dnull) { =09 request.setAttribute("username", = session.getAttribute("username")); =09 =09 } javax.sql.DataSource dataSource; Connection conn; try { dataSource =3D getDataSource(request); conn =3D dataSource.getConnection(); Statement stmt =3D null; ResultSet rs =3D null; String sqlquery=3D"select * from my_table"; sqlquery=3Dsqlquery+"and dcc_forklifts.status=3D\"Active\""; stmt =3D conn.createStatement(); rs=3D stmt.executeQuery(sqlquery); ResultSetMetaData rsmd =3D rs.getMetaData(); int numberOfColumns =3D rsmd.getColumnCount(); Vector rows=3Dnew Vector(); while(rs.next()) {=09 rs=3Dstmt.getResultSet(); Hashtable fields=3Dnew Hashtable(); for(int j=3D1; j<=3DnumberOfColumns;j++) =09 { = fields.put(rsmd.getColumnName(j),rs.getString(rsmd.getColumnName(j)));=09 } rows.add(fields);=09 }=09 request.setAttribute("rows",rows); conn.close(); =09 =09 return mapping.findForward(request.getParameter("page")); }=20 catch (SQLException sqle)=20 { =09 request.setAttribute("val",sqle); return mapping.findForward("sqlexception");=09 } } } In JSP page , I access this vector as Vector rows =3D(Vector)request.getAttribute("rows"); int sz=3Drows.size(); for(int i=3D0;i< sz;i++) { Hashtable row=3D(Hashtable)rows.get(i); ............................... } With regards, Amit Gupta -----Original Message----- From: Manisha Sathe [mailto:manisha_msathe@yahoo.com]=20 Sent: Friday, December 24, 2004 8:55 AM To: tomcat-user@jakarta.apache.org Subject: Newbie question on Database and struts I am new to struts (even new to java also) =20 I have one form developed in struts. What i want to do is depending on = form values, run sql qry in Action form, get result set and display it = on JSP. =20 I have created a databean for the results. But with result set -> How to = create array of databeans ? and how to post it on JSP ? =20 if anybody can pass me the samples pls would be of great help =20 regards Manisha =20 =20 =20 =20 =09 --------------------------------- Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. ------_=_NextPart_001_01C4E96D.D1168E59--