Hi Manisha,

 

I was also struggling with problem similar to you. I came you with following: 

 

package forklifts;

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

import org.apache.struts.action.ActionForm;

 

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import java.util.Collection;

import java.sql.*;

 

public final class registrationAction extends Action {

 

    public ActionForward execute(ActionMapping mapping,

                                 ActionForm form,

                                 HttpServletRequest request,

                                 HttpServletResponse response)

        throws Exception {

        javax.sql.DataSource dataSource;

            Connection conn;

            try {

                        dataSource = getDataSource(request);

                        conn = dataSource.getConnection();

                        Statement stmt = null;

                        ResultSet rs = null;

                        String sqlquery="select * from my_table where 
username='"+request.getParameter("username")+"'";

                        stmt = conn.createStatement();

                        rs=stmt.executeQuery(sqlquery);

                        if(rs.next())

                        {

                              request.setAttribute("msg","<h5 class=error>User 
with username '"+request.getParameter("username")+"' is already registered. Try 
another username.</h5> ");

                                    if(rs!=null)

                                          rs.close();

                                    if(stmt!=null)

                                          stmt.close();

                                    if(conn!=null)

                                          conn.close();

                                    return mapping.findForward("success");    

                        }

                        else

                        {

                              sqlquery="Insert into my_table set 
username='"+request.getParameter("username")+"',password='"+request.getParameter("password")+"',FirstName='"+request.getParameter("FirstName")+"',LastName='"+request.getParameter("LastName")+"',Address='"+request.getParameter("Address")+"',Street='"+request.getParameter("Street")+"',City='"+request.getParameter("City")+"',State='"+request.getParameter("State")+"',Country='"+request.getParameter("Country")+"',Zip='"+request.getParameter("Zip")+"',Email='"+request.getParameter("Email")+"',Phone1='"+request.getParameter("Phone")+"',title='"+request.getParameter("title")+"',company='"+request.getParameter("company")+"',website='"+request.getParameter("website")+"',fax='"+request.getParameter("fax")+"'";

                              try

                              {

                                    stmt = conn.createStatement();

                                    stmt.executeUpdate(sqlquery);

                                    request.setAttribute("msg","<h5 
class=success>Your account created successfully</h5>");

                                    if(rs!=null)

                                          rs.close();

                                    if(stmt!=null)

                                          stmt.close();

                                    if(conn!=null)

                                          conn.close();

                                    return mapping.findForward("success");}

                              catch(SQLException ex1)

                              {

                                    request.setAttribute("msg","<h5 
class=error>Sorry! regsitration failed</h5> ");

                                    return mapping.findForward("sqlexception"); 
    

                              }

                        }

                  }

                  catch(SQLException ex)

                  {

                        request.setAttribute("msg","<h5 class=error>Sorry! 
regsitration failed</h5> ");

                  return mapping.findForward("sqlexception");     

                  }

            }

      }

 

 

I hope above code will give you sufficient idea you to pass data to JSP page.

 

 

-----Original Message-----
From: Manisha Sathe [mailto:[EMAIL PROTECTED] 
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)

 

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.

 

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 ?

 

if anybody can pass me the samples pls would be of great help

 

regards

Manisha

 

 

 

 

 

            

---------------------------------

Do you Yahoo!?

 Read only the mail you want - Yahoo! Mail SpamGuard.

Reply via email to