View Single Post

   
  #2 (permalink)  
Old 04-16-2008, 01: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

Reply With Quote