Unix Technical Forum

Class Cast Exception for DataSource

This is a discussion on Class Cast Exception for DataSource within the pgsql Interfaces jdbc forums, part of the PostgreSQL category; --> 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"**;* ** ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Interfaces jdbc

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-16-2008, 12:36 AM
Raghavendra MB
 
Posts: n/a
Default Class Cast Exception for DataSource

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-16-2008, 12:36 AM
Heikki Linnakangas
 
Posts: n/a
Default Re: Class Cast Exception for DataSource

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("jdbcostgresql:...." );

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

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:40 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com