mark reusen wrote:I printed it in the log and the result after the parse is: "Tue Jun 25 00:00:00 CET 1963", and the gebDatum is: "1963-06-25"
Last I checked, "1963-06-25" is June 26 of the year 1963. This shows you are converting to a date properly so why do you say that it is not working?
Joined: Oct 20, 2010
The result I want is a Date object, so I can use it for updating the Date in the database.
The only thing what I want to happen is converting a String format to a Date format, both look like "1978-02-18".
And are you using some kind of ORM to map an object to your relational database, like Hibernate? Or why do you exactly need a java.sql.Date?
If you have look at the SimpleDateFormat API you'll notice that its parse-method will return a Date object. So that's certainly not the unexpected format after parsing. Furthermore is the java.sql.Date a subclass of the Date class, so you can use its constructor and the getTime-method to create an instance of the desired type.
If you look at the java.sql.Date javadoc, it has a constructor that takes a long as its constructor. The java.util.Date class has a method that returns a long. It should not be hard to convert the two.
and that is because of the unexpected format after parse.......
No, that means the parsing from String to java.util.Date went successfully, but when you insert this in the database, for example using a PreparedStatement, it expects a java.sql.Date object and not a java.util.Date object. (Unfortunately the date and time APIs in Java's standard library are not great, so this is one of those problems you get...).