Re: Class Cast Exception for DataSource - Mailing list pgsql-jdbc

From Heikki Linnakangas
Subject Re: Class Cast Exception for DataSource
Date
Msg-id 45DD773B.2070604@enterprisedb.com
Whole thread Raw
In response to Class Cast Exception for DataSource  ("Raghavendra MB" <mb.ragu@gmail.com>)
List 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:

Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql:....");

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: invalid byte sequence for encoding "UTF8": 0x00
Next
From: Dave Cramer
Date:
Subject: Re: JDBC object factory