Обсуждение: pgsql jdbc db connection weird behaviour

Поиск
Список
Период
Сортировка

pgsql jdbc db connection weird behaviour

От
Venkateswar Reddy Melachervu
Дата:
Hello PGSQL Community,
Love pgsql. But facing this weird problem (detailed below) for past couple of days with pgsql jdbc41 driver with tomcat 8 connection pooling on on jvm1.8 (all on x64 windows 8) with no resolution in sight for casting a jdbc db tomcat pooled connection to PGConnection hitting the wall. 

I am sure not sure if I am doing something silly or it is the limitation of pgsql jdbc41 driver. Did any one face any such issue? Does any one know some way out for this?

Problem:
When I try to cast a DB Connection obtained using tomcat jdbc resource (pooled) to org.postgresql.PGConnection, of course after unwrapping it, execution is running into exception with the message: (java.lang.ClassCastException) java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4Connection cannot be cast to org.postgresql.PGConnection

Gotcha
Weird enough, if I do not use a pooled connection but create a single db stand-alone connection in the java code - dbCon = .getConnection(...) and cast this to org.postgresql.PGConnection - to my surprise - it's successful. Feels weird!

Environment
OS : WIndows 8 x64
JRE : java version "1.7.0_51"
Tomcat : 8.0 (x64)
Connection pooling : Tomcat jdbc connection pooling with database as JDBC resource (org.apache.tomcat.jdbc.pool.DataSourceFactory)
PostgreSQL server : v9.3 x64
Pgsql JDBC version : JDBC41 Postgresql Driver, Version 9.3-1101 (stored in Tomcat lib dir and linked from there to my project)

-- 
Regards,
Venkateswar Reddy Melachervu
"...dare to dream, care to win..."

Re: pgsql jdbc db connection weird behaviour

От
Steven Schlansker
Дата:
On Mar 30, 2014, at 12:10 AM, Venkateswar Reddy Melachervu <vmelachervu@gmail.com> wrote:

> Hello PGSQL Community,
> Love pgsql. But facing this weird problem (detailed below) for past couple of days with pgsql jdbc41 driver with
tomcat8 connection pooling on on jvm1.8 (all on x64 windows 8) with no resolution in sight for casting a jdbc db tomcat
pooledconnection to PGConnection hitting the wall.  
>
> I am sure not sure if I am doing something silly or it is the limitation of pgsql jdbc41 driver. Did any one face any
suchissue? Does any one know some way out for this? 
>
> Problem:
> When I try to cast a DB Connection obtained using tomcat jdbc resource (pooled) to org.postgresql.PGConnection, of
courseafter unwrapping it, execution is running into exception with the message: (java.lang.ClassCastException)
java.lang.ClassCastException:org.postgresql.jdbc4.Jdbc4Connection cannot be cast to org.postgresql.PGConnection 

Almost always this is caused by having more than one driver jar file available in your class path.  In particular,
bundlinga driver in the Tomcat lib/ directory as well as within your application itself is sure to cause problems. 

That’s where I would look first.

Hope that helps,
Steven



Re: pgsql jdbc db connection weird behaviour

От
Venkateswar Reddy Melachervu
Дата:
Steve,
I've checked it - appears no duplicate jdbc drivers..:-(


On Sun, Mar 30, 2014 at 10:59 AM, Steven Schlansker <stevenschlansker@gmail.com> wrote:

On Mar 30, 2014, at 12:10 AM, Venkateswar Reddy Melachervu <vmelachervu@gmail.com> wrote:

> Hello PGSQL Community,
> Love pgsql. But facing this weird problem (detailed below) for past couple of days with pgsql jdbc41 driver with tomcat 8 connection pooling on on jvm1.8 (all on x64 windows 8) with no resolution in sight for casting a jdbc db tomcat pooled connection to PGConnection hitting the wall.
>
> I am sure not sure if I am doing something silly or it is the limitation of pgsql jdbc41 driver. Did any one face any such issue? Does any one know some way out for this?
>
> Problem:
> When I try to cast a DB Connection obtained using tomcat jdbc resource (pooled) to org.postgresql.PGConnection, of course after unwrapping it, execution is running into exception with the message: (java.lang.ClassCastException) java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4Connection cannot be cast to org.postgresql.PGConnection

Almost always this is caused by having more than one driver jar file available in your class path.  In particular, bundling a driver in the Tomcat lib/ directory as well as within your application itself is sure to cause problems.

That’s where I would look first.

Hope that helps,
Steven




--
Regards,
Venkateswar Reddy Melachervu
"...dare to dream, care to win..."

Re: pgsql jdbc db connection weird behaviour

От
Dave Cramer
Дата:
Even if there was a duplicate the Jdbc4Connection should be able to be cast.

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On Sun, Mar 30, 2014 at 2:47 AM, Venkateswar Reddy Melachervu <vmelachervu@gmail.com> wrote:
Steve,
I've checked it - appears no duplicate jdbc drivers..:-(


On Sun, Mar 30, 2014 at 10:59 AM, Steven Schlansker <stevenschlansker@gmail.com> wrote:

On Mar 30, 2014, at 12:10 AM, Venkateswar Reddy Melachervu <vmelachervu@gmail.com> wrote:

> Hello PGSQL Community,
> Love pgsql. But facing this weird problem (detailed below) for past couple of days with pgsql jdbc41 driver with tomcat 8 connection pooling on on jvm1.8 (all on x64 windows 8) with no resolution in sight for casting a jdbc db tomcat pooled connection to PGConnection hitting the wall.
>
> I am sure not sure if I am doing something silly or it is the limitation of pgsql jdbc41 driver. Did any one face any such issue? Does any one know some way out for this?
>
> Problem:
> When I try to cast a DB Connection obtained using tomcat jdbc resource (pooled) to org.postgresql.PGConnection, of course after unwrapping it, execution is running into exception with the message: (java.lang.ClassCastException) java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4Connection cannot be cast to org.postgresql.PGConnection

Almost always this is caused by having more than one driver jar file available in your class path.  In particular, bundling a driver in the Tomcat lib/ directory as well as within your application itself is sure to cause problems.

That’s where I would look first.

Hope that helps,
Steven




--
Regards,
Venkateswar Reddy Melachervu
"...dare to dream, care to win..."

Re: pgsql jdbc db connection weird behaviour

От
"peter.penzov"
Дата:
Hi All,
   I have the same problem. Did you managed to solve it? Can you give some
advice?



--
View this message in context:
http://postgresql.nabble.com/pgsql-jdbc-db-connection-weird-behaviour-tp5797924p5901547.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


Re: pgsql jdbc db connection weird behaviour

От
"peter.penzov"
Дата:
Hi All,
   I have the same problem. Did you managed to solve it? Can you give some
advice?



--
View this message in context:
http://postgresql.nabble.com/pgsql-jdbc-db-connection-weird-behaviour-tp5797924p5901547.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


Re: pgsql jdbc db connection weird behaviour

От
Gavin Flower
Дата:
On 03/05/16 07:30, peter.penzov wrote:
> Hi All,
>     I have the same problem. Did you managed to solve it? Can you give some
> advice?
>
>
>
> --
> View this message in context:
http://postgresql.nabble.com/pgsql-jdbc-db-connection-weird-behaviour-tp5797924p5901547.html
> Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
>
>
Hi Peter,

It is a very good idea to quote the relevant part of the email you are
referring to, as others may have had the same problem, but your email is
insufficient to identify the problem - referring to another web site is
bad etiquette (except when the other web site is the topic!).


Cheers,
Gavin



Re: pgsql jdbc db connection weird behaviour

От
Gavin Flower
Дата:
On 03/05/16 07:30, peter.penzov wrote:
> Hi All,
>     I have the same problem. Did you managed to solve it? Can you give some
> advice?
>
>
>
> --
> View this message in context:
http://postgresql.nabble.com/pgsql-jdbc-db-connection-weird-behaviour-tp5797924p5901547.html
> Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
>
>
Hi Peter,

It is a very good idea to quote the relevant part of the email you are
referring to, as others may have had the same problem, but your email is
insufficient to identify the problem - referring to another web site is
bad etiquette (except when the other web site is the topic!).


Cheers,
Gavin