从datetime本地html输入插入psqldb

iszxjhcz  于 2021-07-05  发布在  Java
关注(0)|答案(1)|浏览(230)

我无法将datatime的正确格式放入insert语句(更多的是prepared语句)。
从html(作为setter)输入变量为“string”-

<input  style="border:1px solid grey; width: 100%"  type="datetime-local" id="maintsd" name="maintsd">

设定者:

public void setMaintsd(String maintsd) {
        this.maintsd = maintsd;
    }

准备好的声明:

ps.setTimestamp(2, obj_modeSwitch_Bean.getMaintsdI());

setter将值作为 2020-09-05T23:59 现在,prepared语句没有设置settimestamp(my function to fetch)或setdate(func to fetch datetime)
准备好的语句或参数有变化吗?

b09cbbtk

b09cbbtk1#

preparedstatement#设置对象

下面是一个例子:

PreparedStatement st = conn.prepareStatement("INSERT INTO mytable (columnfoo) VALUES (?)");
LocalDateTime ldt = LocalDateTime.parse("2020-09-05T23:59", DateTimeFormatter.ISO_LOCAL_DATE_TIME);
st.setObject(1, ldt);
st.executeUpdate();
st.close();

你的情况应该是这样的

LocalDateTime ldt = LocalDateTime.parse(obj_modeSwitch_Bean.getMaintsdI(), DateTimeFormatter.ISO_LOCAL_DATE_TIME);
ps.setObjec(2, ldt);

相关问题