Re: jdbc and postgresql function session question

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Michael Moore <michaeljmoore(at)gmail(dot)com>, postgres list <pgsql-sql(at)postgresql(dot)org>
Subject: Re: jdbc and postgresql function session question
Date: 2016-05-31 22:36:06
Message-ID: CAKFQuwY5E6hf=WxVMcc3afu2cW8GGLhu9TQmJPW2aA-fWCMHaw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, May 31, 2016 at 6:01 PM, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> On 05/31/2016 02:20 PM, Michael Moore wrote:
>
>> When the postgres jdbc driver calls a postgres function, does it get a
>> new session every time? If I create a PREPARED statement on the first
>> call, will it still be available on the 2nd call? If not, is there any
>> way I could get the prepared statement to be used on successive calls?
>>
>
> I think this is going to need more explanation, so:
>
> 1) When you say session are you talking about connection or a transaction?
> A function will run in its own transaction each time, but can be run
> multiple times in a connection.
>
> 2) Where is the PREPARED statement being built, in the function or outside
> it?
>
> 3) Can show an outline of what you are doing?
>
>
​Making some assumptions...

con = DriverManager.getConnection(); -- opens a database session

Any JDBC Statement objects you create using this con are able to access
named PostgreSQL PREPAREd statement previously created.
However, beware of
DEALLOCATE ALL
[1]

While you are unlikely to issue such a command explicitly you need to be
aware that connection poolers may do so in some configurations.

​CallableStatement stmt = con.prepareCall(sql); --sees any session-scoped
data since con was created.​

con.close();​

​ -- now the database session is done​

https://www.postgresql.org/docs/current/static/sql-deallocate.html

​David J.​

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Moore 2016-06-01 14:29:20 Re: jdbc and postgresql function session question
Previous Message Adrian Klaver 2016-05-31 22:01:04 Re: jdbc and postgresql function session question