By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,654 Members | 1,517 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,654 IT Pros & Developers. It's quick & easy.

cannot save date from user input to database

P: 1
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.
Expand|Select|Wrap|Line Numbers
  1. DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
  2. Date startDate=user.getDate_from();
  3.                 dateFormat.format(startDate);
  4.                         user.setDate_to(startDate);
  6. Date endDate=user.getDate_to();
  7.                         dateFormat.format(endDate);
  8.                         user.setDate_to(endDate); 
Mar 13 '12 #1
Share this Question
Share on Google+
2 Replies

P: 13,264
If you are using JDBC then you set the date via PreparedStatement.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.
Mar 13 '12 #2

P: 4
if the type of column which in your table is date, maybe, you should change the format
Jun 5 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.