Skip site navigation (1) Skip section navigation (2)

Re: Control characters in sql statements close db connection

From: Barry Lind <blind(at)xythos(dot)com>
To: "Mushran, Vrinda" <Vrinda(at)netopia(dot)com>
Cc: "'pgsql-jdbc(at)postgresql(dot)org'" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Control characters in sql statements close db connection
Date: 2003-01-17 17:52:03
Message-ID: (view raw or whole thread)
Lists: pgsql-jdbc

Yes I would say this is expected behavior.  If you use the regular 
Statement object it is your responsibility to properly quote and escape 
the data.  However if you use a PreparedStatement then the driver 
handles it for you.

So you would issue the following via a PreparedStatement:


and then do a stmt.setString(1,"'^(at)`^]:u'");


Mushran, Vrinda wrote:
> I am using PostgresSQL 7.2.1 and jdbc driver jar pg72jdbc2.jar that I
> downloaded from
> Below is the select statement that fails:
> '^(at)`^]:u'"
> Executing the statement results in:
> java.sql.SQLException: ERROR:  Unterminated quoted string
>         at org.postgresql.core.QueryExecutor.execute(
>         at org.postgresql.Connection.ExecSQL(
>         at org.postgresql.jdbc2.Statement.execute(
>         at org.postgresql.jdbc2.Statement.executeQuery(
>         at
> org.postgresql.jdbc2.PreparedStatement.executeQuery(PreparedStatement
> .java:99)
>         at TestPostgresJDBC.main(
> Running this statement also causes the Connection to be closed.
> My questions are:
> 1. Is this expected behavior? I don't expect the connection to be lost.
> Ideally, unless there is such data, nothing is returned for this resultset
> or an exception is thrown but the connection is kept open.
> 2. Is there a way to escape such characters. I did not find any
> documentation on that.
> 3. Is this a  jdbc driver issue or the server itself chokes on these
> characters? My guess is that the server chokes.
> 4. Is there any solution for this problem? The application does need to deal
> with control characters.
> Any help is appreciated.
> Vrinda Mushran
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

In response to


pgsql-jdbc by date

Next:From: Joel HockDate: 2003-01-17 18:09:45
Subject: insertRow and updateable resultset
Previous:From: Tom LaneDate: 2003-01-17 17:50:28
Subject: Re: Control characters in sql statements close db connection

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group