pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: Assad Jarrahian <jarraa@gmail.com>
Cc: David Wall <d.wall@computer.org>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Prepared statements and default values
Date: Mon, 9 Jan 2006 23:21:10 -0500
Message-ID: <377962F9-1235-4413-94AA-3E2BCBA12B59@fastcrypt.com> (raw)
In-Reply-To: <4bd3e1480601092002m7f637397nef9654c5014f4785@mail.gmail.com>
References: <4bd3e1480601091924q54cfee5cs1c6744638e650fff@mail.gmail.com>
	<43C32A5D.8020807@computer.org>
	<4bd3e1480601092002m7f637397nef9654c5014f4785@mail.gmail.com>

Actually, I don't think not specifying the column will work. This  
works for insert, but not update.


I don't think there is a way using JDBC, as you can't even use the  
keyword DEFAULT. The driver won't let you bind a string to a non- 
string parameter.

Dave
On 9-Jan-06, at 11:02 PM, Assad Jarrahian wrote:

> thanks for your response David!
>
> Is that the only way, cause that surely does not seem easy when you
> have say 20 columns, of which 15 have default values.
>
> given all the combinations (sometimes this set of column values is
> needed to be default, otherwise another set .... and so on.
>
> Am I stuck with writing out all possible statements ...or is there  
> another way?
>
> thanks.
> -assad
>
>
> On 1/9/06, David Wall <d.wall@computer.org> wrote:
>> You'll probably need to use two statements, so that when you want  
>> to use
>> the default, you don't specify anything, and when you want a special
>> value, you use the command you gave.
>>
>> If you want the default, use:
>>
>> UPDATE usersettings SET serverurl = ? where username = ?
>>
>> If you want to specify, then use:
>>
>> UPDATE usersettings SET gpsfrequency = ? , serverurl = ? where  
>> username = ?
>>
>> David
>>
>>
>> Assad Jarrahian wrote:
>>
>>> I have a preparedStatement with the following query
>>> "UPDATE usersettings SET gpsfrequency = ? , serverurl = ? where
>>> username = ? ;";
>>>
>>> In the db, the table userSettings has a default value specified for
>>> gps_frequency .
>>>
>>> So when I write code
>>> if (client.getSettings().getField 
>>> (Settings.GPS_FREQUENCY).compareTo(""))==0)
>>>       <what goes here> //pick up the default value from the db.
>>> else
>>>       setUserSettings.setInt(++i,
>>> Integer.parseInt(client.getSettings().getField 
>>> (Settings.GPS_FREQUENCY)));
>>>
>>>
>>> <what goes here> .. I basically want to send something that lets the
>>> db know to use the DEFAULT value. (its of type int0)
>>>
>>> So what does go here?
>>>
>>> any help would be much appreciated.
>>>
>>> -a
>>>
>>> ---------------------------(end of  
>>> broadcast)---------------------------
>>> TIP 2: Don't 'kill -9' the postmaster
>>>
>>>
>>>
>>
>> ---------------------------(end of  
>> broadcast)---------------------------
>> TIP 6: explain analyze is your friend
>>
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                http://archives.postgresql.org
>




view thread (5+ messages)  latest in thread

Message-ID: <377962F9-1235-4413-94AA-3E2BCBA12B59@fastcrypt.com>
Permalink:  ../377962F9-1235-4413-94AA-3E2BCBA12B59@fastcrypt.com/
Also on:    postgresql.org/message-id/377962F9-1235-4413-94AA-3E2BCBA12B59@fastcrypt.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: pg@fastcrypt.com, jarraa@gmail.com, d.wall@computer.org
  Subject: Re: Prepared statements and default values
  In-Reply-To: <377962F9-1235-4413-94AA-3E2BCBA12B59@fastcrypt.com>
  References: <4bd3e1480601091924q54cfee5cs1c6744638e650fff@mail.gmail.com> <43C32A5D.8020807@computer.org> <4bd3e1480601092002m7f637397nef9654c5014f4785@mail.gmail.com> <377962F9-1235-4413-94AA-3E2BCBA12B59@fastcrypt.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox