Re: PreparedStatement parameters and mutable objects - Mailing list pgsql-jdbc

From Dave Cramer
Subject Re: PreparedStatement parameters and mutable objects
Date
Msg-id 1073656006.1690.52.camel@localhost.localdomain
Whole thread Raw
In response to Re: PreparedStatement parameters and mutable objects  (Kris Jurka <books@ejurka.com>)
Responses Re: PreparedStatement parameters and mutable objects
Re: PreparedStatement parameters and mutable objects
List 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


pgsql-jdbc by date:

Previous
From: Csaba Nagy
Date:
Subject: Re: [BUG] - Invalid UNICODE character sequence found
Next
From: "Antonio Gallardo"
Date:
Subject: Re: [BUG] - Invalid UNICODE character sequence found(0xc000)