pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David G Johnston <david.g.johnston@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: How to implement a dynamic string into a sql statement?
Date: Tue, 26 Aug 2014 11:37:32 -0700 (PDT)
Message-ID: <1409078252506-5816363.post@n5.nabble.com> (raw)
In-Reply-To: <53FCC2CB.6080507@web.de>
References: <53FCC2CB.6080507@web.de>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

howalt wrote
> So, it seems that PSQL has problems with the ? in the prepared 
> statement. Does anyone know a solution for this problem?

The most secure way to handle this would be to create a custom pl/pgsql
function and build the dynamic sql string in there and execute it.  You can
then make use of the "quote_ident" function to help make sure that the sql
you are creating is valid and resistant to injection.


> I also tried using normale statement, but this is giving me a findbug 
> error that I try to pass a nonconstant string to an execute method on an 
> sql statement. So I really dont know how to get rid of this problem

I have no clue what a "findbug error" is.  I presume it is warning you about
sql injection risks.  In which case you will have to override the error
since the only way to do what you want, directly in Java, is to risk sql
injection.  Thus you have to be especially careful to validate the user
input.

Again, you can offload that responsibility to PostgreSQL itself by simply
passing the variables, as values, into a function on the server and let that
function convert them into identifiers.

David J.




--
View this message in context: http://postgresql.1045698.n5.nabble.com/How-to-implement-a-dynamic-string-into-a-sql-statement-tp581...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (5+ messages)  latest in thread

Message-ID: <1409078252506-5816363.post@n5.nabble.com>
Permalink:  ../1409078252506-5816363.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1409078252506-5816363.post@n5.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: david.g.johnston@gmail.com
  Subject: Re: How to implement a dynamic string into a sql statement?
  In-Reply-To: <1409078252506-5816363.post@n5.nabble.com>
  References: <53FCC2CB.6080507@web.de> <1409078252506-5816363.post@n5.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox