Lists: | pgsql-jdbc |
---|
From: | "Raghavendra MB" <mb(dot)ragu(at)gmail(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Class Cast Exception for DataSource |
Date: | 2007-02-22 06:20:01 |
Message-ID: | aa36b6870702212220j7ecae30alb114e71f54e2aca3@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | 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
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: | 45DD773B.2070604@enterprisedb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
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:
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql:....");
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com