Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以在Java中调用DATE_ADD()并将值存储在临时日期变量中?_Java_Mysql_Date - Fatal编程技术网

是否可以在Java中调用DATE_ADD()并将值存储在临时日期变量中?

是否可以在Java中调用DATE_ADD()并将值存储在临时日期变量中?,java,mysql,date,Java,Mysql,Date,我对MySQL数据库中的Date添加天数表示怀疑。 以下是我的代码: res=stat.executeQuery("select st_date from tmp1 where st_date = '"+t1.getText()+"'"); while(res.next()) { System.out.println(res.getDate(1)); int i=0; while(i<14) { statement.executeUpdate

我对MySQL数据库中的
Date
添加天数表示怀疑。 以下是我的代码:

res=stat.executeQuery("select st_date from tmp1 where st_date = '"+t1.getText()+"'");
while(res.next())
{
    System.out.println(res.getDate(1));
    int i=0;
    while(i<14)
    {
        statement.executeUpdate("Insert into datetab values(DATE_ADD('"
            +res.getDate("st_date")+"',INTERVAL 1 DAY),'"+tempname+"')");
        i=i+1;
    }
}
res=stat.executeQuery(“从tmp1中选择st_日期,其中st_日期=””+t1.getText()+”);
while(res.next())
{
系统输出println(res.getDate(1));
int i=0;
而
如果tmp1表中的日期是28-12-2000,那么在使用date_add()执行insert查询之后,会发生13个新插入,但所有这些插入都是“29-12-2000”

因为这正是您所要求的。您的insert语句是:

"Insert into datetab values(DATE_ADD('" + res.getDate("st_date") + 
    "',INTERVAL 1 DAY),'" + tempname + "')"
由于
read.getDate
在循环中没有变化,因此在每个迭代中插入相同的值


使用
“Interval”+i+“DAY”而不是
“Interval 1 DAY”
,应该插入不同的日期。这就是您要寻找的吗?

我不知道您的目标是什么,但据我所知,如果您有“28-12-2000”日期值为X,您想在第二天插入的值是:X+1 Hanks brother…我当时在想,我这么做了,但忘记了加上+号,错误显示为不兼容的类型。谢谢。您为我节省了一个小时。没有工作。没有错误,但没有更新任何内容。这不太可能,这是y中的其他错误吗我们的代码?我建议您逐步完成程序,将参数分配给
executeUpdate
字符串
,并在调用
executeUpdate
之前打印它,然后尝试在交互式sql会话中执行它