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
Try to add explicit type casting
change+ "(?,?,?)";
to+ "(?,?, CAST (? AS time))";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With