Is there any way, via JDBC, to send the DEFAULT
placeholder explicitly, like in INSERT INTO sometables VALUES (blah, DEFAULT)
? (I'm almost certain the answer is "no", but I'm looking for JDBC-expert confirmation).
Say you had a PreparedStatement
like:
INSERT INTO mytable(a, b) VALUES (?, ?)
for table:
CREATE TABLE mytable (
a integer,
b integer default some_function()
);
and you wanted to use the database-set DEFAULT
for mytable.b
in some executions in a batch but not others.
In regular SQL you'd write:
INSERT INTO mytable(a, b) VALUES (1, 42)
INSERT INTO mytable(a, b) VALUES (2, DEFAULT);
...
or of course:
INSERT INTO mytable(a, b) VALUES (1, 42)
INSERT INTO mytable(a) VALUES (2);
... but you can't do this via JDBC. setString("DEFAULT")
will of course not send the DEFAULT
keyword, just the string-literal 'DEFAULT'
.
Is there a way to set a placeholder-parameter that means DEFAULT
in any widely used drivers?
I don't see a way to do it with the standard API and spec.
I'm imagining something like:
pstmt.setObject(2, Postgresql.DEFAULT, Types.OTHER);
where Postgresql.DEFAULT
is a special placeholder instance, since there doesn't seem to be a setDefault()
method for PreparedStatement
.
Does any existing driver support this?
See Question&Answers more detail:
os