Error: <column-name> has time without a time zone, but the expression has a character that changes

I am using postgresql database. I am inserting values ​​into a database from a java class. I declared a field that has a data type without a time zone as a string. I do not know how to parse and send it to a database that matches the data type? How to do it?

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: CREATED_DATE has a time without a time zone, but the expression has a character that changes Hint: try making an expression

+4
source share
1 answer

Try adding explicit type casting

change
+ "(?,?,?)";



+ "(?,?, CAST (? AS time))";

+2
source

Source: https://habr.com/ru/post/1528929/


All Articles