Skip to content
Advertisement

org.postgresql.util.PSQLException: ERROR: column is of type date but expression is of type integer: cannot write date into postgres using java

I’m trying to insert a record inside my table but I cannot insert any values into the Date column.

This is the code I use to make an insert:

JavaScript

How I call this function:

JavaScript

The fullstack trace I get:

JavaScript

Advertisement

Answer

The correct solution to this problem is to use a PreparedStatement – do not concatenate parameters into SQL strings.

Your problem with the date parameter is only the tip of the iceberg.
The next problem you’ll get is, if Peter O'Donnel signs up.

So you should use something like this:

JavaScript
Advertisement