How to pass dates in Java to a database?

3

I'm trying to pass a date in "yyyy/MM/dd HH:mm:ss" format to the database so I'm using Date() and SimpleDateFormat() , however it returns me a string . Is there any way I can return a date or if there is any conversion to it?

    
asked by anonymous 16.03.2015 / 15:09

1 answer

2

It has a way but it depends on what you need. You have to see what your database is waiting for. You are sending the data in a different type than the one expected by the database. So you need to find out what the expected type is and send it this way.

SimpleDateFormat() is to mount strings even and not to format dates, because dates have no format, dates are dates. Only texts that show dates are formatted. On a date what matters is the value contained in it and not the way it is presented.

In fact, the author discovered that he needed to use Timestamp() .

    
16.03.2015 / 15:52