pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Class Cast Exception for DataSource
2+ messages / 2 participants
[nested] [flat]

* Class Cast Exception for DataSource
@ 2007-02-22 06:20 Raghavendra MB <mb.ragu@gmail.com>
  2007-02-22 10:58 ` Re: Class Cast Exception for DataSource Heikki Linnakangas <heikki@enterprisedb.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Raghavendra MB @ 2007-02-22 06:20 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

I am using Postgres 8.2 version database and *postgresql-8.2-504.jdbc3.jar*
driver.

Snippet of code:


*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.



regards

Raghu

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Class Cast Exception for DataSource
  2007-02-22 06:20 Class Cast Exception for DataSource Raghavendra MB <mb.ragu@gmail.com>
@ 2007-02-22 10:58 ` Heikki Linnakangas <heikki@enterprisedb.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Heikki Linnakangas @ 2007-02-22 10:58 UTC (permalink / raw)
  To: Raghavendra MB <mb.ragu@gmail.com>; +Cc: 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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2007-02-22 10:58 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-02-22 06:20 Class Cast Exception for DataSource Raghavendra MB <mb.ragu@gmail.com>
2007-02-22 10:58 ` Heikki Linnakangas <heikki@enterprisedb.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox