datetime :日期必须以年-月-日的顺序给出,yyyy-mm-dd hh:mm:ss按你的说法,你可以用 TIMESTAMP(6)  YYMMDD

解决方案 »

  1.   

    不知道JSP中有没有session?
    以前偶用PHP中有。。可以用session+cookie
      

  2.   

    Mysql 
    的datetime字段你插入时候用NOW() 就可以了,不需要jsp来生成的时间
    如 INSERT INTO TABLE voteTime values (NOW())时间比较 
    mysql的函数很多 比如你用TO_DAYS(NOW()) 和 TO_DAYS(voteTime) 比较就可以达到你需要的1天内不能重复投票
      

  3.   

    TO:jhwl(hj)
    你的那种方法不行,我一改用NOW()就报错,如果不用生成的话就没办法显示正确的本地时间TO:sgdb(神天月晓)
    我用jsp生成的时间就是yyyy-mm-dd hh:mm:ss的,但是插入的时候总是说非法的日型类型。你的那个timestamp(6)具体怎么做可以告诉一下么?
      

  4.   

    字段类型设成TIMESTAMP ,长度6
      

  5.   

    //define datetime(yyyy-mm-dd hh-mm-ss)
    Calendar now = Calendar.getInstance();
    String date = DateFormat.getDateTimeInstance().format(now.getTime());
      

  6.   

    TO: gsen(进入就是上帝) 
    不行,还是一样报错。TO: flylyke(爱就像英雄莫问出处)
    String型无法插入到mysql的datetime类型的字段中,我试过很多遍了。TO: AlexJava2(+黑色契约+)
    这个方法生成的日期也是String型的,可以插入么?
      

  7.   

    to  runbing(帅青蛙) 
    使用NOW()来插入数据库的datetime,timestamp,date类型的字段是不可能报告错误的。
    mysql 假定voteTime为你的投票时间
    sql 的语句 
    INSERT INTO yourtable (voteTime) values (NOW());绝对无问题
    String 格式的时间yyyy-mm-dd一样可以插入
    INSERT INTO yourtable (voteTime) values ('2004-02-01');
    上面的你用executeUpdate()的方法就ok
    如果你是用的PreparedStatment setTimestamp()的方法插入就不能用mysql的NOW(),肯定报错java那里认识这个NOW()哟同样String格式的时间也是不行的
    PreparedStatment stm=
    con.prepareStatement("INSERT INTO yourtable voteTime  VALUES (?)");
    stm.setTimestamp(new java.sql.Timestamp(System.currentTimeMillis()));
    stm.executeUpdate();
      

  8.   

    stm.setTimestamp(new java.sql.Timestamp(System.currentTimeMillis()));
    这句忘了个参数
    stm.setTimestamp(1,new java.sql.Timestamp(System.currentTimeMillis()));
      

  9.   

    奇怪,我一用NOW()马上就报错,错误的箭头都是指在NOW()这个地方,而我换成其他的,页面都可以运行,只有在添加的时候会出错。
    出错提示:
    You have an error in you SQL syntax. Check you manual that corresponds to you MySQL server version for the right syntax to use near '(ipAddress,ipDate) value ('127.0.0.1',2004-2-2 14:23:32)' at
      

  10.   

    String ipAddress = request.getRemoteAddr();
    if(read.isUseIP(ipAddress))

    out.println("<script>alert('您已经投过票了');history.back();</script>");
    else{
    String[] colums = request.getParameterValues("colum");
    java.util.Date nowTime = new java.util.Date();
    //java.util.Date nowTime = new java.util.Date();
    for(int i = 0; i < colums.length; i++){
    openDate.getStmt().executeUpdate("update columMDB set columHits = columHits + 1 where columID = " + colums[i]);
    try{
    openDate.getStmt().executeUpdate("update ipMDB set ipDate = '" + nowTime.toLocaleString() + "' where ipAddress = '" + ipAddress + "'");
    }catch(Exception e){
    System.out.println("更新IP失败" + e.getMessage());
    }
    try{
    openDate.getStmt().executeUpdate("insert into (ipAddress,ipDate) values ('" + ipAddress + "'," + nowTime.toLocaleString() + ")");
    }catch(Exception ex){
    System.out.println("添加IP失败" + ex.getMessage());
    }
    //out.println(colums[i]);
    }  //end for
    }
      

  11.   

    update ipMDB set ipDate = '" + nowTime.toLocaleString() + "' where ipAddress = '" + ipAddress + "'"
    改为
    update ipMDB set ipDate =NOW() where ipAddress = '" + ipAddress + "'"insert into (ipAddress,ipDate) values ('" + ipAddress + "'," + nowTime.toLocaleString() + ")"
    改为
    insert into (ipAddress,ipDate) values ('" + ipAddress + "',NOW())ipDate为datetime或date或timestamp字段