Re: preparedStatement, Batch, DEFAULT, getGeneratedKeys() - Mailing list pgsql-jdbc

From dmp
Subject Re: preparedStatement, Batch, DEFAULT, getGeneratedKeys()
Date
Msg-id 528A5F6A.8030508@ttc-cmc.net
Whole thread Raw
In response to preparedStatement, Batch, DEFAULT, getGeneratedKeys()  (Martin Eriksson <M.Eriksson@albourne.com>)
List 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.



pgsql-jdbc by date:

Previous
From: Martin Eriksson
Date:
Subject: preparedStatement, Batch, DEFAULT, getGeneratedKeys()
Next
From: Rahul Ranjan
Date:
Subject: Fwd: postgres join query.