将datetime类型的sql请求中的值赋给java.util.Date变量

时间:2016-03-03 22:14:00

标签: java sql date datetime time

我试过了..

MCorr mc = new MCorr();
PreparedStatement ps = conn.prepareStatement("SELECT * FROM mcorr");
ResultSet rs = ps.executeQuery();
while(rs.next()){
    mc.setDateMaint(rs.getDate("dateMaint"));
}

然后这个

MCorr mc = new MCorr();
PreparedStatement ps = conn.prepareStatement("SELECT * FROM mcorr");
ResultSet rs = ps.executeQuery();
 while(rs.next()){
    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-mm-dd hh:MM");
    java.util.Date date = sdf1.parse(rs.getString("dateMaint"));
    java.sql.Date sqlDate = new Date(date.getTime()); 
    mc.setDateMaint(sqlDate );
}

但无论如何它只显示没有小时和分钟的日期..

在MCorr课程中

 private Date dateMaint;

我该怎么办才能得到日期和时间..

0 个答案:

没有答案