From: thomas at tada.se (Thomas Hallgren) Date: Sat, 16 Apr 2011 07:27:27 +0200 Subject: [Pljava-dev] retaining prepared statements across stored procedure calls In-Reply-To: References: <4DA36735.4080402@tada.se> Message-ID: <4DA928BF.7080100@tada.se> Yes, there are reasons. One reason is that calls can come from functions with different SecurityManagers. Keeping a state between those calls could introduce security leaks and IIRC, the statement is attached to an SPI context. Another reason is memory preservation. There is no natural way of doing a proper clean up unless you do it when the call ends. There might be other reasons as well. It's been a while since I looked at the actual code. - thomas On 2011-04-16 01:25, Johann 'Myrkraverk' Oskarsson wrote: > >>> When >>> I call callProc in psql, I get a warning about closing 1 >>> forgotten statement. Does that mean I cannot have prepared >>> statements lingering around after each store procedure >>> invocation? >>> >> Yes it does. >> - thomas > > Is there a good reason for this? > > Is there something wrong with initializing prepared statements within a static initializer? > > PreparedStatment prep; > > static { > //... > prep = connection.prepareStatement( "select 1;" ); > //... > } > > public static useStatement() { > //... > prep.executeQuery(); > //... > } >