Re: PreparedStatement parameters and mutable objects

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Kris Jurka <books(at)ejurka(dot)com>
Cc: Oliver Jowett <oliver(at)opencloud(dot)com>, "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: PreparedStatement parameters and mutable objects
Date: 2004-01-09 13:46:46
Message-ID: 1073656006.1690.52.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Well there is some hint that this is incorrect:

pstmnt = con.prepareStatment("insert into foo values(?,?)");

pstmnt.setString(1,"abcd");

for( i=0; i< 5; i++)
{
Integer intx = new Integer(i);
pstmnt.setInt(2,intx)
pstmnt.executeUpdate();
}

The above code should insert ("abcd", 0 .. 4 ) into five rows

The point being that the value for setXXX does not change until setXXX
is called.

This is from section 24.1.2 in the JDBC api tutorial

In all I'm sort of sitting on the fence here. I guess we could try it
and see how many people get tripped up?

Dave

On Fri, 2004-01-09 at 03:18, Kris Jurka wrote:
> On Fri, 9 Jan 2004, Oliver Jowett wrote:
>
> > > I'm saying that doing it this way will likely expose buggy code, which
> > > we will end up having to figure out why it doesn't work, when the user
> > > says "my code used to work, and now it doesn't", plus they don't send us
> > > code to look at.
> >
> > How far do we go to support buggy code though? If we can't make this
> > sort of change, we lose several opportunities for optimization.
>
> I don't think you can label this as buggy code unless you can point to the
> spec and say where it is disallowed. It is certainly something that looks
> dangerous and is unlikely to be written by the average developer, but that
> doesn't make it illegal. I lean towards the notion that when I say setXXX
> that's the time the value must be saved because that's certainly more
> intuitive and specific than "sometime later when the driver decides to."
>
> Kris Jurka
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
--
Dave Cramer
519 939 0336
ICQ # 1467551

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Antonio Gallardo 2004-01-09 14:05:49 Re: [BUG] - Invalid UNICODE character sequence found(0xc000)
Previous Message Martin Holz 2004-01-09 11:18:31 Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and