如下一段程序:
java.sql.Date dt=new java.sql.Date(year-1900,month-1,day);
String sql="Insert into stock values(?,?,?,?,?,?,?,?,?)";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setDate(3,dt);
每次执行到pstmt.setDate(3,dt)的时候报错“java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]没有执行可选特性”,
请教各位大侠如何解决这个问题?谢谢!

解决方案 »

  1.   


    // 这不是完整程序吧.
    java.sql.Date dt=new java.sql.Date(year-1900,month-1,day); 
    String sql="Insert into stock values(?,?,?,?,?,?,?,?,?)"; 
    PreparedStatement pstmt=conn.prepareStatement(sql); 
    pstmt.setDate(3,dt);
      

  2.   

    呵呵,楼上,只是其中一段代码,数据库中第三个字段是datetime类型,执行setDate为什么会报错呢?
      

  3.   

    datetimesmalldatetimeTIMESTAMPjava.sql.Timestampsqlserver中的 datetime应该对应java.sql中的timestamp ,不是date
      

  4.   


    new Date(System.currentTimeMillis());//可否?
    或者System.currentTimeMillis();
      

  5.   

    JDK文档对void setDate(int parameterIndex,Date x)的解释是“Sets the designated parameter to the given java.sql.Date value using the default time zone of the virtual machine that is running the application.”,第二个参数类型应该是java.sql.Date类型吧,用Timestamp和new Date(System.currentTimeMillis())试过也不能解决问题,比较奇怪。
      

  6.   

    数据库中也用Date应该就没问题了。
      

  7.   

    SQL SERVER中datetime对应java中java中timeStamp类型,问题已解决,谢谢各位。