How to set a DateTime variable in SQL Server 2008?

前端 未结 10 1849
暗喜
暗喜 2020-12-30 20:15

SQL Server 2008 is not doing what I expected with DateTime. It doesn\'t let me set DateTime variables, no matter what date format I use.

Wh

10条回答
  •  被撕碎了的回忆
    2020-12-30 20:50

     1. I create new Date() and convert her in String .
     2. This string I set in insert.
    
     **Example:**  insert into newDate(date_create) VALUES (?)";
    
     ...
     PreparedStatement ps = con.prepareStatement(CREATE))
            ps.setString(1, getData());
            ps.executeUpdate();
      ...}
    
       private String getData() {
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd hh:mm:ss");
         return  sdf.format(new java.util.Date());
        }
    
     **It is very important format** = "yyyy-M-dd hh:mm:ss"
    

提交回复
热议问题