case 2: in jdbc program. ERROR: 42804: column "a" is of type boolean but expression is of type integer at character 25 HINT: You will need to rewrite or cast the expression. LOCATION: transformAssignedExpr, parse_target.c:529 STATEMENT: insert into test values ($1)
when this case, statement is 'insert', I think binding values already sent to server, then server can display these.
They aren't yet sent to the server, so it cannot display them.
Sure, your code says "setInteger(1)". But that doesn't send anything to the server, it just stores it in the PreparedStatement object in Java.
PgJDBC does a Parse/Bind/Execute when you actually execute your prepared statement after setting parameters. The parse phase, which comes first, does NOT yet send the parameters your program supplied to the server.
So PgJDBC has the parameters, but the server, which is what is generating the error, does not.
I want see that
"ERROR: 42804: column "a" is of type boolean but expression is of type integer(input value = 24) at character 25"
You can't, and I don't see any realistic way to make that happen except for switching to client-side parameter binding (interpolation). Which is a bad idea for performance and all sorts of other reasons. If you really must do so, force the version 2 protocol in PgJDBC.
Really, the problem is your code: you should setBool not setInteger here. That's really all there is too it.