java.sql.TimeStamp才行,java.sql.Date丢失时间信息

解决方案 »

  1.   

    使用PreparedStatement的setTimestamp
      

  2.   

    String sql = "INSERT INTO table (date1) VALUES(?)"
    PreparedStatement pstatement = connection.prepareStatement( sql );
    java.sql.TimeStamp time = new java.sql.TimeStamp(new Date.getTime());
    pstmt.setTimestamp(1,time);
    pstmt.excuteUpdate();
      

  3.   

    其实数据库都有时间操作函数的!
    你把它放入sql就行了!
    比如mysql:
     "insert into  table1(str1,curdate) values('a string',now())"
      

  4.   

    我这样实现的:
    Timestamp objToday = new java.sql.Timestamp(System.currentTimeMillis() );当然,你的方法也对。
    多谢你的帮忙!