Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Date -> to MySql Time

Tags:

java

mysql

jdbc

I have a Date format in java that I need to save as a Time format in MySQL. Is there a way to just get the time part from the date? I know Dat.gettime() that returns a long but I just need the Time in MySql

Any suggestions...

Thx all ..

like image 497
Darth Blue Ray Avatar asked Apr 23 '26 16:04

Darth Blue Ray


1 Answers

Using a PreparedStatement together with a java.sql.Time object created from your java.util.Date should work:

java.util.Date myDate = ....
java.sql.Time theTime = new java.sql.Time(myDate.getTime());
PreparedStatement pstmt = ...
pstmt.setTime(1, theTime);

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!