0

I have a variable named targetdate and I would like to insert a value in my form.

In my Controller, I have this:

public static int addStudent(Student studentBean){  
   int status=0;  
   try{  
       Connection con=getConnection();  
       PreparedStatement ps=con.prepareStatement("insert into students (targetdate) values(?)");  
       ps.setDate(1,studentBean.getTargetdate());    
       status=ps.executeUpdate();  
   }catch(Exception e){System.out.println(e);}  
   return status;  
}

My problem is the line below:

ps.setDate(1,studentBean.getTargetdate()); 

I have an error message:

the method setDate(int, java.sql.Date) in the type preparedstatement is not applicable for the argument (int, java.util.Date)

I am beginner in Java, I don't understand the problem.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
joel
  • 21
  • 5

1 Answers1

1

Use this:

ps.setDate(1,new java.sql.Date(studentBean.getTargetdate().getTime())); 
Sanjeev Saha
  • 2,632
  • 1
  • 12
  • 19