Skip site navigation (1) Skip section navigation (2)

Re: Class Cast Exception for DataSource

From: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
To: Raghavendra MB <mb(dot)ragu(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Class Cast Exception for DataSource
Date: 2007-02-22 10:58:03
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
Raghavendra MB wrote:
> *String postgresDataSource = **"org.postgresql.Driver"**;*
> **
> *Class dataSourceClass = Class.forName(postgresDataSource);*
> *dataSource = (DataSource) dataSourceClass.newInstance();*
> **
> *I am getting *ClassCast exception when i try to run the code in my java
> application.
> Please resolve this problem.

org.postgresql.Driver doesn't implement the javax.sql.DataSource interface.

If you want a DataSource, just use "new 
org.postgresql.ds.PGSimpleDataSource()" or "new 
org.postgresql.ds.PGPoolingDataSource()" if you want pooling.

If you don't want to use a DataSource, you should be doing:

Connection conn = DriverManager.getConnection("jdbc:postgresql:....");

   Heikki Linnakangas

In response to

pgsql-jdbc by date

Next:From: Dave CramerDate: 2007-02-22 13:06:34
Subject: Re: JDBC object factory
Previous:From: Oliver JowettDate: 2007-02-22 08:54:01
Subject: Re: invalid byte sequence for encoding "UTF8": 0x00

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group