[英]Error: the <column-name> is of time without time zone but expression is of type character varying
i am using a postgresql database. 我正在使用postgresql数据库。 I insert the values to the database from a java class. 我从java类中将值插入数据库。 I have declared the field which is of datatype time without time zone as a String. 我已经声明了没有时区的数据类型时间字段作为字符串。 I am not knowing how to parse and send it to database which matches the data type? 我不知道如何解析并将其发送到与数据类型匹配的数据库? How do I do this? 我该怎么做呢?
public static void User(Form t)
{
String insertTableSQL = "INSERT INTO DBUSER"
+ "(USER_ID, USERNAME,CREATED_DATE) VALUES"
+ "(?,?,?)";
PreparedStatement ps = dbConnection.prepareStatement(insertTableSQL);
ps.setString(1, t.getUserID());
ps.setString(2, t.getuserName());
ps.setString(3, t.getTime());
ps.executeUpdate();
}
Error: Error: the CREATED_DATE is of time without time zone but expression is of type character varying Hint: try to cast the expression 错误:错误:CREATED_DATE是没有时区的时间,但表达式的类型为字符变化提示:尝试强制转换表达式
Try to add explicit type casting 尝试添加显式类型转换
change 更改
+ "(?,?,?)";
to 至
+ "(?,?, CAST (? AS time))";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.