From: | David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: How to implement a dynamic string into a sql statement? |
Date: | 2014-08-26 18:37:32 |
Message-ID: | 1409078252506-5816363.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-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-tp5816355p5816363.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | JasmineLiu | 2014-08-27 07:43:18 | Re: invalid byte sequence for encoding "UTF8": 0x00 |
Previous Message | David G Johnston | 2014-08-26 18:26:58 | Re: How to implement a dynamic string into a sql statement? |