RE: JDBC 'Unterminated quoted string'

From: Peter Mount <petermount(at)maidstone(dot)gov(dot)uk>
To: "'Christopher Farley'" <chris(at)northernbrewer(dot)com>, Grant Finnemore <gaf(at)ucs(dot)co(dot)za>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: RE: JDBC 'Unterminated quoted string'
Date: 2000-11-10 09:19:29
Message-ID: 1B3D5E532D18D311861A00600865478CF1B50E@exchange1.nt.maidstone.gov.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Agreed. I'm doing another blitz on JDBC tomorrow, so I'll do the deed then.

Peter

--
Peter Mount
Enterprise Support Officer, Maidstone Borough Council
Email: petermount(at)maidstone(dot)gov(dot)uk
WWW: http://www.maidstone.gov.uk
All views expressed within this email are not the views of Maidstone Borough
Council

-----Original Message-----
From: Christopher Farley [mailto:chris(at)northernbrewer(dot)com]
Sent: Thursday, November 09, 2000 7:53 AM
To: Grant Finnemore
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [INTERFACES] JDBC 'Unterminated quoted string'

If you setString(1,null), it does work.

I am actually doing a setString(1,String.valueOf('\0')), which causes the
unterminated string error.

Although this didn't fail under the previous RDBMS (PervasiveSQL), I
have considered that setting a Java char to '\0' is just bad programming
practice. However:

- Both Postgresql and Java evaluate '\0' as ''.

- You can't set a Java char to ''.

- Many people have a need to map chars to a RDBMS

So it seems reasonable to me that the JDBC driver should escape NULL chars
as '\\0' rather than pass the character unparsed where it will be treated
as a NUL terminator when it appears in a C string.

Damn these primitive types in Java!

----
Christopher Farley
Northern Brewer / 1150 Grand Avenue / St. Paul, MN 55105
www.northernbrewer.com

On Thu, 9 Nov 2000, Grant Finnemore wrote:

> Christopher,
>
> Yep, this is the correct place to discuss bugs...
>
> I tried the following code, and it seems to work. Is this similar to what
you are
> trying to do?
>
> import java.sql.*;
>
> public class JDBCTest {
> public static void main(String[] args) throws Exception {
> Class.forName("org.postgresql.Driver");
> Connection conn =
> DriverManager.getConnection("jdbc:postgresql://localhost/test",
> "jms", "jms");
> /* Before running this class, ensure that the database is created.
> * CREATE DATABASE test;
> * CREATE TABLE t ( aa char(1) );
> */
> PreparedStatement ps =
> conn.prepareStatement("insert into t values (?)");
> ps.setString(1, null);
> ps.executeUpdate();
> }
> }
>
> Also, what version of the driver are you using - is it off CVS, the
version 7.0.x
> tarballs, something else?
>
> Regards,
> Grant
>
> Christopher Farley wrote:
>
> > Grant,
> > Thanks for the -d2 tip, it will make my life a lot easier for quite
> > some time!
> > Actually, I already tested the 'unescaped single quote' theory, and
the
> > JDBC driver *does* escape them for you.
> > The problem in my case seems to be that the JDBC driver is throwing
the
> > 'unterminated quoted string' because I am inserting a null value into a
> > char(1) field. I do not have any 'not null' constraints on the field.
> > I can easily work around this problem now that I understand it, but
I'm
> > pretty sure this is not correct behavior for the JDBC driver. Is this
the
> > proper forum to report bugs, if this is indeed a bug?
> >
> > ----
> > Christopher Farley
> > Northern Brewer / 1150 Grand Avenue / St. Paul, MN 55105
> > www.northernbrewer.com
>
> --
> > Poorly planned software requires a genius to write it
> > and a hero to use it.
>
> Grant Finnemore BSc(Eng) (mailto:gaf(at)ucs(dot)co(dot)za)
> Software Engineer Universal Computer Services
> Tel (+27)(11)712-1366 PO Box 31266 Braamfontein 2017, South Africa
> Cell (+27)(82)604-5536 20th Floor, 209 Smit St., Braamfontein
> Fax (+27)(11)339-3421 Johannesburg, South Africa
>
>

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Peter Mount 2000-11-10 09:26:02 RE: installation
Previous Message Peter Mount 2000-11-10 09:17:21 RE: JDBC 'Unterminated quoted string'