Re: preparedStatement, Batch, DEFAULT, getGeneratedKeys()

From: dmp <danap(at)ttc-cmc(dot)net>
To: PostgreSQL JDBC <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: preparedStatement, Batch, DEFAULT, getGeneratedKeys()
Date: 2013-11-18 18:41:46
Message-ID: 528A5F6A.8030508@ttc-cmc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Martin Eriksson wrote:
> Hi,
>
> I've been scourging the mailing list for a while and general
> google/stack overflow looking for a solution dealing with JDBC, and
> batching..
>
> 2. I've been searching and searching for a way to set "DEFAULT" on a
> prepared statement, is it even possible? e.g. "INSERT INTO a (id)
> VALUES (?) and then doing something like
> prepStatment.setInt(1,"DEFAULT"); I have found no way of doing
> this... when doing big batches that would be very nice indeed....
> to not having to split everything depending on the existence of
> data in default fields
>
> Cheers
> Martin
>

Hello Martin,

With regard to 2.

Some databases do allow you to insert default in the prepared statement,
but I have not found that to be the case with PostgreSQL to my knowledge.

Default can be inserted though via the following.

Given:

CREATE TABLE "keY_tAble2" (
"Host" char(60) NOT NULL default '',
"Db" char(64) NOT NULL default '',
"Username" char(16) NOT NULL default '',
Select_priv boolean NOT NULL default TRUE,
PRIMARY KEY ("Host","Db","Username")
);

To give the default value to "Host" Use the following prepared statement.

INSERT INTO "public"."keY_tAble2" ("Db", "Username", "select_priv") VALUES (?, ?, ?)

I guess as you said though this does not help with batching.

danap.

Browse pgsql-jdbc by date

  From Date Subject
Next Message Rahul Ranjan 2013-11-19 09:10:08 Fwd: postgres join query.
Previous Message Martin Eriksson 2013-11-18 14:57:21 preparedStatement, Batch, DEFAULT, getGeneratedKeys()