Re: Class Cast Exception for DataSource
| От | Heikki Linnakangas |
|---|---|
| Тема | Re: Class Cast Exception for DataSource |
| Дата | |
| Msg-id | 45DD773B.2070604@enterprisedb.com обсуждение исходный текст |
| Ответ на | Class Cast Exception for DataSource ("Raghavendra MB" <mb.ragu@gmail.com>) |
| Список | 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 по дате отправления: