日期:2014-05-20  浏览次数:20730 次

一个java.sql.date的问题,用pstmt.setDate怎么样才能插入yyyy-MM-dd HH:mm:ss
使用以下的语句
pstmt.setDate( "UpdateDate ",   rs.getDate( "UpdateDate "));
为什么插入数据库的是yyyy-MM-dd
而不是yyyy-MM-dd   HH:mm:ss
我想插入的是yyyy-MM-dd   HH:mm:ss这种格式的该怎么做了

------解决方案--------------------
用java.sql.Timestamp
------解决方案--------------------
看看我写的一个方法,是将现在的时间转化为yy-MM-dd HH:mm:ss的,仅供参考:
/**
* 取出现在的时间,年-月-日 小时-分-秒
* @param currentTime long
* @return String
*/
public String getCurrentDate(long currentTime){
DateFormat df=new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss ");
String time = df.format(new Date(currentTime));
return time;
}