Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XMLck-0000B3-8k for pgsql-jdbc@arkaria.postgresql.org; Tue, 26 Aug 2014 18:37:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XMLcj-0004AN-PQ for pgsql-jdbc@arkaria.postgresql.org; Tue, 26 Aug 2014 18:37:41 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XMLcj-0004AG-4m for pgsql-jdbc@postgresql.org; Tue, 26 Aug 2014 18:37:41 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XMLcb-0004iS-1u for pgsql-jdbc@postgresql.org; Tue, 26 Aug 2014 18:37:39 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1XMLca-0000VQ-GV for pgsql-jdbc@postgresql.org; Tue, 26 Aug 2014 11:37:32 -0700 Date: Tue, 26 Aug 2014 11:37:32 -0700 (PDT) From: David G Johnston To: pgsql-jdbc@postgresql.org Message-ID: <1409078252506-5816363.post@n5.nabble.com> In-Reply-To: <53FCC2CB.6080507@web.de> References: <53FCC2CB.6080507@web.de> Subject: Re: How to implement a dynamic string into a sql statement? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org 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. -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc