cannot save date from user input to database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tqa89
    New Member
    • Mar 2012
    • 1

    cannot save date from user input to database

    Hi,
    When user input the date,I want to save it to database. But I'm not sure about the date format,whether I should change the format?
    I'm using getter and setter method to save to database.I'm using db2
    This is my code.
    Code:
    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    Date startDate=user.getDate_from();
    				dateFormat.format(startDate);
    						user.setDate_to(startDate);
    						
    Date endDate=user.getDate_to();
    						dateFormat.format(endDate);
    						user.setDate_to(endDate);
    thanks
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    If you are using JDBC then you set the date via PreparedStateme nt.setDate which takes a java.sql.Date object.

    You only have to worry about date formats when displaying the date to a user or getting a date from a user, not when inserting it into the database.

    Comment

    • keep1to2
      New Member
      • May 2012
      • 4

      #3
      if the type of column which in your table is date, maybe, you should change the format

      Comment

      Working...