gpt4 book ai didi

java - SQL异常: inconsistent datatypes: expected TIMESTAMP got NUMBER

转载 作者:行者123 更新时间:2023-12-02 05:40:37 24 4
gpt4 key购买 nike

我已经在带有时间戳数据库的sql数据库中创建了一个列。我正在尝试从 java 运行下面给出的插入查询

st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
st.executeUpdate("insert into profmessage values('" + uid + "','" + from + "','" + to + "','" + msg + "','" + dt + "',1,0,'" + new java.sql.Timestamp(new Date().getTime()) + "')");
st.close();

正在显示

sqlexception  inconsistent datatypes: expected TIMESTAMP got NUMBER

最佳答案

我认为你应该使用PreparedStatement(这也有利于避免SQL注入(inject)),并像这样插入时间戳的值:

preparedStatement.setTimestamp(theNumberOfTimestampOccurenceInYourQery, new java.sql.Timestamp(new Date().getTime()));

关于java - SQL异常: inconsistent datatypes: expected TIMESTAMP got NUMBER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24548563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com