File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes couldn't access data using Dao Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "couldn Watch "couldn New topic

couldn't access data using Dao

sudha javvadi
Ranch Hand

Joined: Mar 23, 2007
Posts: 97
Hi ranchers,

This is my first data access program. I am able to connect to database using getConnection() method,but I am not able to insert data into the table "USERS". I couldn't understand what is going wrong. Could you please guide me. Following is the part of Action and dao programs.

public class UserRegistrationAction extends Action{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
UserRegistrationDao urd=new UserRegistrationDao();
public void insert()
UserRegistrationForm userForm= new UserRegistrationForm();

PreparedStatement ps= con.prepareStatement("insert into USERS" + "(EMAIL,FIRST_NAME,LAST_NAME,PASSWORD,PHONE,FAX)" + "values(?,?,?,?,?,?)");
catch(Exception ex)
System.out.println("exception occured in dao layer"); //directly comming to this point
Sudarshan Chakrabarty
Ranch Hand

Joined: Apr 10, 2008
Posts: 38
Hi Sudha,

In your insert method, you created a new object of class UserRegistrationForm method using

Then you are calling a method on the userForm object

But, you haven't populated the userForm object yet, so your userForm.getEmail() will throw a null pointer exception. Hence, you are getting the Exception.
So, you need to populate the userForm object before calling any method on it.
Hope this helps .
sudha javvadi
Ranch Hand

Joined: Mar 23, 2007
Posts: 97
Hi sudarshan,

Thank you for your reply. I dont want to put all the insert code in ActionForm execute method. I need the form object in dao class. How can I get that form object in dao class? I tried different ways but no luck. please guide me.

Thank you,
sudha javvadi
Ranch Hand

Joined: Mar 23, 2007
Posts: 97

problem solved. I got it.

I agree. Here's the link:
subject: couldn't access data using Dao
It's not a secret anymore!