Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: the <column-name> is of time without time zone but expression is of type character varying

i am using a postgresql database. I insert the values to the database from a java class. 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

like image 665
Vidya Avatar asked Oct 21 '22 13:10

Vidya


1 Answers

Try to add explicit type casting

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

like image 181
Iv Ov Avatar answered Oct 23 '22 03:10

Iv Ov