Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datetime type in Mysql database

Tags:

java

mysql

I have a field in my database (MYSQL) with datetime type (with this format 2011-05-18 16:29:31), I dont know this type! because I Have to convert a String to this type. I have found java.sql.Date and java.sql.Timestamp and not datetime!

like image 345
rym Avatar asked Jul 09 '11 12:07

rym


1 Answers

mysql datetime maps to a java.sql.Timestamp - they are both a "date plus a time"

To convert a String to a Date, use this code:

java.util.Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2011-05-18 16:29:31");
java.sql.Timestamp timestamp = new java.sql.Timestamp(date.getTime());
like image 78
Bohemian Avatar answered Sep 19 '22 02:09

Bohemian