Java: creating a date object from a string and inserting into MySQL

六眼飞鱼酱① 提交于 2019-12-02 11:37:12

PreparedStatement.setDate takes a java.sql.Date, not a java.util.Date.

(Out of interest, how come you're not actually seeing this as a compile-time error? Your life will become a lot easier if you can resolve compilation failures without having to get to that point in a test run...)

My guess is that you mixed java.util.Date and java.sql.Date ...

String to MySQL Date/Time

import java.sql.Date;
import java.sql.Time;

 statement.setDate(4, Date.valueOf("2009-08-26"));
 statement.setTime(5, Time.valueOf("12:04:08"));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!