Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 87AC59FBC6E for ; Thu, 22 Feb 2007 06:58:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 54256-06 for ; Thu, 22 Feb 2007 06:58:22 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.172]) by postgresql.org (Postfix) with ESMTP id 522119FBC46 for ; Thu, 22 Feb 2007 06:58:26 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so66825ugf for ; Thu, 22 Feb 2007 02:58:24 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=NG9TiUT+0HA8w449sJIhb92FE4UVkx4XQDIjQAjaexG3w8+BCJvA1CKbvUspiKw8RI0VZ5EyS0YfufXz59gtMLPgz16ea4jsmuWj/zCAF9cfohhuEJ0aljODmcRxppmO0NCVB8heocXqC5/ng8Yh6IVf/e/QcINy+BgLAU+njvQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=MNAs1L2CCKBnGTboLjAxlbdh9IegZLkzNa1K5mYHcVQ6TCtNARor4tsEuBn93NGhNlLp092+8gZtTaY7rUzYxdEIsCiT5eXwh1SQefubKjp1ebDx7pOdCo1+8YgbEAeUsaLBeubWpA+ps956iR9PEBjCkd+ceLmskfTkNIo6rjI= Received: by 10.67.121.15 with SMTP id y15mr443364ugm.1172141904780; Thu, 22 Feb 2007 02:58:24 -0800 (PST) Received: from ?172.24.32.51? ( [62.232.55.118]) by mx.google.com with ESMTP id o30sm482170ugd.2007.02.22.02.58.23; Thu, 22 Feb 2007 02:58:23 -0800 (PST) Message-ID: <45DD773B.2070604@enterprisedb.com> Date: Thu, 22 Feb 2007 10:58:03 +0000 From: Heikki Linnakangas User-Agent: Icedove 1.5.0.8 (X11/20061116) MIME-Version: 1.0 To: Raghavendra MB CC: pgsql-jdbc@postgresql.org Subject: Re: Class Cast Exception for DataSource References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/118 X-Sequence-Number: 16674 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