RE: JDBC problem with DELETE

From: Peter Mount <petermount(at)it(dot)maidstone(dot)gov(dot)uk>
To: "'Dnesbitt(at)encryptix(dot)com'" <Dnesbitt(at)encryptix(dot)com>, "Peter Mount (Home)" <peter(at)retep(dot)org(dot)uk>, Peter Mount <petermount(at)it(dot)maidstone(dot)gov(dot)uk>, pgsql-interfaces(at)postgresql(dot)org
Subject: RE: JDBC problem with DELETE
Date: 2000-07-31 06:47:33
Message-ID: 1B3D5E532D18D311861A00600865478CF1B182@exchange1.nt.maidstone.gov.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

PreparedStatement is the proper way, because it allows for differences
between implementations of SQL and how data types are handled. It's mainly
for code that can use different database engines.

ie: setString() will automatically add quotes whereas you have to do this
yourself with Statement. Also, not all quotes are '. There's a method in
DatabaseMetaData that returns the current quoting character (which we hard
code to '). This allows some engines to use different characters.

Also when you start using some of the more special types, PreparedStatement
will handle them better than you could - look at
setTimestamp()/getTimestamp() for an example... It's easier to keep the
driver in line with the backend (the format returned changed) than to change
everyone's code.

Peter

--
Peter Mount
Enterprise Support
Maidstone Borough Council
Any views stated are my own, and not those of Maidstone Borough Council

-----Original Message-----
From: Dnesbitt(at)encryptix(dot)com [mailto:Dnesbitt(at)encryptix(dot)com]
Sent: Saturday, July 29, 2000 3:09 AM
To: peter(at)retep(dot)org(dot)uk; petermount(at)it(dot)maidstone(dot)gov(dot)uk;
pgsql-interfaces(at)postgresql(dot)org
Cc: Dnesbitt(at)encryptix(dot)com
Subject: RE: [INTERFACES] JDBC problem with DELETE

Thanks, Peter. Please let me know if you see anything.

I can't see how my Java code could be losing the single quotes. It is such
a simple statement. But then again, I have made obvious coding errors that
I just can't see a time or two in the past. :-)

Why is PreparedStatement the proper safe way? From a coding perspective, it
takes more lines of code and it would seem to also require slightly more
computation as well.

Regards,
//Dave

> -----Original Message-----
> From: Peter Mount [mailto:peter(at)retep(dot)org(dot)uk]
> Sent: Thursday, July 27, 2000 10:52 AM
> To: Dnesbitt(at)encryptix(dot)com; petermount(at)it(dot)maidstone(dot)gov(dot)uk;
> pgsql-interfaces(at)postgresql(dot)org
> Cc: Dnesbitt(at)encryptix(dot)com
> Subject: Re: [INTERFACES] JDBC problem with DELETE
>
>
> I'm not sure, but it might be loosing the quote somewhere.
>
> The proper safe way is to use PreparedStatement. I'll try it
> here just to
> make sure it isn't a bug though.
>
> Peter
>
> --
> Peter T Mount peter(at)retep(dot)org(dot)uk, peter(at)retepdigital(dot)com,
> me(at)petermount(dot)com
> Homepage: http://www.retep.org.uk Contact details @
> http://petermount.com
> PostgreSQL JDBC: http://www.retep.org.uk/postgres/
> Java PDF generator: http://www.retep.org.uk/pdf/
>
> ----- Original Message -----
> From: <Dnesbitt(at)encryptix(dot)com>
> To: <petermount(at)it(dot)maidstone(dot)gov(dot)uk>;
> <pgsql-interfaces(at)postgresql(dot)org>
> Cc: <Dnesbitt(at)encryptix(dot)com>
> Sent: Thursday, July 27, 2000 5:55 PM
> Subject: RE: [INTERFACES] JDBC problem with DELETE
>
>
> > Peter,
> >
> > The sql does work from psql.
> >
> > I also tried your suggestion about using PreparedStatement and that
> worked!
> >
> > Am I doing something wrong with Statement or is it a bug?
> >
> > Regards,
> > file://Dave
> >
> > > -----Original Message-----
> > > From: Peter Mount [mailto:petermount(at)it(dot)maidstone(dot)gov(dot)uk]
> > > Sent: Wednesday, July 26, 2000 11:48 PM
> > > To: 'Dnesbitt(at)encryptix(dot)com'; pgsql-interfaces(at)postgresql(dot)org
> > > Subject: RE: [INTERFACES] JDBC problem with DELETE
> > >
> > >
> > > Does this happen when you run the sql from psql?
> > >
> > > How about using PreparedStatement instead of Statement? It
> > > would then handle
> > > the quoting correctly (which is what I'm thinking is going
> > > wrong here).
> > >
> > > Peter
> > >
> > > --
> > > Peter Mount
> > > Enterprise Support
> > > Maidstone Borough Council
> > > Any views stated are my own, and not those of Maidstone
> > > Borough Council
> > >
> > >
> > > -----Original Message-----
> > > From: Dnesbitt(at)encryptix(dot)com [mailto:Dnesbitt(at)encryptix(dot)com]
> > > Sent: Thursday, July 27, 2000 5:41 AM
> > > To: pgsql-interfaces(at)postgresql(dot)org
> > > Cc: Dnesbitt(at)encryptix(dot)com
> > > Subject: [INTERFACES] JDBC problem with DELETE
> > >
> > >
> > > The following piece of code:
> > >
> > > stmt.executeUpdate("delete from friend where
> name='"+someName+"'");
> > >
> > > is returning:
> > >
> > > SQLException: java.sql.SQLException: ERROR: Attribute
> > > 'John Doe' not
> > > found
> > >
> > > where someName is "John Doe".
> > >
> > > Any ideas? The row where name='John Doe' is definitely in
> > > the table and I
> > > can execute the statement without problems from psql.
> > >
> > > Thanks in advance for your help.
> > >
> > > Regards,
> > > file://Dave
> > >
>

Browse pgsql-interfaces by date

  From Date Subject
Next Message Cedar Cox 2000-07-31 07:22:31 PGAccess and UNIX sockets
Previous Message David Lloyd-Jones 2000-07-31 06:28:30 Re: PSQL Working, but PGAccess Not Connecting.