PreparedStatement pstmt3=con.prepareStatement("insert Master(CompName,NoOfShares,PurRate,PurDate,CurrRate)"+
                            "values (?,?,?,?,?)");
            pstmt3.setString(1,"sina.com");
            pstmt3.setInt(2,888);
            pstmt3.setFloat(3,388);
            pstmt3.setDate(4,这里的时间格式应该怎么写);

解决方案 »

  1.   

    不知道这样行不行...
    to_date("2000-01-01","YYYY-MM-DD")
      

  2.   

     pstmt3.setDate(4,这里的时间格式应该怎么写);=========================
    一般都用setString ,在内部实现
      

  3.   


    System.currentTimeMillis();??
      

  4.   

    SimpleDateFormat sdf= new SimpleDateFormat("yyyy-mm-dd hh:MM:ss");
    pstmt3.setDate( sdf.format(new Date()) );
    这样就应该可以的,格式还可以随你设
      

  5.   


    Date date=new Date();
    SimpleDateFormat format= new SimpleDateFormat("yyyy-mm-dd hh:MM:ss"); 
    pstmt3.setDate( format.parse(date)); 
    因为"pstmt3.setDate"知道你插入的是时间型的而不是以字符串的形式插入的,
    所以可以用上面的方法.6楼说的是以字串的形式插入.
      

  6.   

    不好意思.
    刚才没有写好就发上去了.
    ------------------------------Date date=new Date();
    SimpleDateFormat format= new SimpleDateFormat("yyyy-mm-dd hh:MM:ss"); 
     String strdate=format.format(date);
     try {
    Date date1=format.parse(strdate);
    pstmt3.setDate(date1);
    } catch (ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }----------------------------
    呵呵.
    不好意思.
      

  7.   

    SimpleDateFormat format= new SimpleDateFormat("yyyy-mm-dd hh:MM:ss"); 
    标红的你就可以设置时间格式了.