But the problem is this that in this db's field accept date in format of yyyy-mm-dd.
While my user interface sends in dd-mm-yyyy. On middle tier Iv tried to use java.text.Dateformat but still its not working.
Could you please tell me a way to change representation of Date.
Originally posted by Paul Sturrock:
Use a PreparedStatement and bind your data parameters as Date objects. Then you have no formatting issues.
Well, Its not adding proper data in db.
If im doing
In DB, its inserting 0006-06-26.
And by the way, In DB this field's type is TIMESTAMP. But im not able to use timestamp as well in java.
Originally posted by Horatio Westock:
Hi. I'm not familiar with firebird, so not sure what the problem is?
Did you try something like this?
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");
Date myDate = dateFormat.parse( myDateString );
preparedStatement.setTimestamp( myDate );
setTimeStamp must need a TimeStamp object as a Parameter. And TimeStamp is a subclass of java.util.Data
Originally posted by Adeel Ansari:
Donot care about the representation of the date while writing it to DB. But when it comes to presentation then offcourse you need to format it.
Use the prepared statement, as Paul said.
Even its not storing data in db properly, its changing date 0021-12-03
which represents the 26th June 0006 apperently. However:
is the 1st of January 2003.
Presuming your front end is allowing users to input dates in this format: dd-MM-yyyy, then you need to add something to parse these strings there (have a look at java.text.SimpleDateFormat). Once you've parsed it, you can pass it about as a Date object. 10-01-2003, 2003-01-01, 1st Jan 2003, 01-Jan-2003, 1/1/2003 etc. are all different presentations of the Date value 1041379200000. When you bind this Object to a PreparedStatement it is the value not the format which is bound.