1

I'm new to struts. I'm using jquery datepicker plugin. I want to get a date(and time) from the user and insert it into the database. When i submit the form, the action class receives 0 value if i set the datatype to long(or int) and it receives null when i set datatype to anything else. I'm not sure what datatype should be used and how it is to be done. Please help

JSP form

<s:form name="register-complaint" action="registerComplaint" method="post">
  :
  :
<sj:datepicker id="date_time" name='date_and_time' label="Date and Time of Offence"         
timepicker="true" timepickerAaPm="true" timepickerGridHour="1" timepickerGridMinute="5"             
timepickerStepMinute="5"/>
:
:
</s:form>

Action class

private Date dateAndTimeOfOccurance;
// or long

public String execute throws Exception{
  :
   ps.setDate(13, (java.sql.Date) getDateAndTimeOfOccurance());
   // or       ps.setLong(13, getDateAndTimeOfOccurance());
  :
}
maxx777
  • 1,320
  • 1
  • 20
  • 37

1 Answers1

0

Your name attribute is wrong. Since your variable is

private Date dateAndTimeOfOccurance;

you need to write that in JSP:

    <sj:datepicker name = "dateAndTimeOfOccurance" 
                     id = "date_time"  
                  label = "Date and Time of Offence"         
             timepicker = "true" 
         timepickerAaPm = "true" 
     timepickerGridHour = "1" 
   timepickerGridMinute = "5"             
   timepickerStepMinute = "5"/>

Obviously remember to generate a Getter and a Setter for that variable in the Action.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • should it be java.util.Date or java.sql.Date? – maxx777 Apr 03 '14 at 14:45
  • 1
    always java.util.Date – Andrea Ligios Apr 03 '14 at 14:45
  • Have you tried @maxx777 ? Did it work ? Please remember to accept the answer if it helped. – Andrea Ligios Apr 03 '14 at 15:37
  • thanks. your reply was helpful. but now i'm now facing some other problem. i'm trying to conver `java.util.Date` to `java.sql.Date` using `ps.setDate(13, new java.sql.Date(getDateAndTimeOfOccurance().getTime()));` but this statement is throwing exception java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent datatypes: expected DATE got NUMBER http://stackoverflow.com/questions/530012/how-to-convert-java-util-date-to-java-sql-date – maxx777 Apr 03 '14 at 17:18
  • Strange, btw you should post it as a separate question, including the stacktrace – Andrea Ligios Apr 03 '14 at 22:05
  • that problem has been solved. it was because of symantically incorrect prepareStatement. btw thanks for showing your interest (y) – maxx777 Apr 03 '14 at 22:29