Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 676119FA217 for ; Fri, 29 Dec 2006 05:15:22 -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 30409-08 for ; Fri, 29 Dec 2006 05:15:09 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.187]) by postgresql.org (Postfix) with ESMTP id 2FB849FA102 for ; Fri, 29 Dec 2006 05:15:12 -0400 (AST) Received: by nf-out-0910.google.com with SMTP id x4so5923767nfb for ; Fri, 29 Dec 2006 01:15:10 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:x-enigmail-version:content-type:content-transfer-encoding:sender; b=IRMM0T1r0Z0GA4X46obUvIYJ3hMMY4/rFnC73iTD75WYkFh4NjTwBIOoGtHXeaM6AV+FNo+pGqEu6MicnP+yR66OPMs+DtJl4/ebRMqgm6iGvPqLDuDsHJNvGRH98ILF3BsJUmRL0/41t0bpkXOdKc6lJdtT56VmLZTwXE7zZQ8= Received: by 10.48.210.16 with SMTP id i16mr7462633nfg.1167383710038; Fri, 29 Dec 2006 01:15:10 -0800 (PST) Received: from ?192.168.1.33? ( [82.247.148.168]) by mx.google.com with ESMTP id o9sm25971806nfa.2006.12.29.01.15.09; Fri, 29 Dec 2006 01:15:09 -0800 (PST) Message-ID: <4594DC9A.6050407@free.fr> Date: Fri, 29 Dec 2006 10:15:06 +0100 From: "Xavier Poinsard" User-Agent: Thunderbird 1.5.0.8 (X11/20061115) MIME-Version: 1.0 To: Danish Siddiqui CC: pgsql-jdbc@postgresql.org Subject: Re: Error while trying to connect to postgresql References: <4594C087.6040204@vertex.co.in> In-Reply-To: <4594C087.6040204@vertex.co.in> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/128 X-Sequence-Number: 16360 Sorry, I answered too quickly to your email. Your compilation problem is that you must catch SQLException and ClassNotFoundException using the java try-catch syntax. See http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html Regards. Danish Siddiqui a écrit : > Hi, > Can some one help me out with this problem. Ive been searching around > for some help but couldnt find any... > > Im trying to connect PostgreSQL with Java.. > > import java.sql.*; > > class PostgreSQLTest{ > public static void main(String[] args){ > Class.forName("org.postgresql.Driver"); > String url="jdbcostgresql://localhost/postgres"; > Connection db = DriverManager.getConnection("url", "postgres", ""); > > System.out.println("Connection Created"); > db.close(); > } > } > > # javac PostgreSQLTest.java > > PostgreSQLTest.java:5: unreported exception > java.lang.ClassNotFoundException; must be caught or declared to be thrown > Class.forName("org.postgresql.Driver"); > ^ > PostgreSQLTest.java:7: unreported exception java.sql.SQLException; must > be caught or declared to be thrown > Connection db = DriverManager.getConnection("url", "postgres", ""); > ^ > PostgreSQLTest.java:10: unreported exception java.sql.SQLException; must > be caught or declared to be thrown > db.close(); > ^ > 3 errors > > > # echo $CLASSPATH > :/usr/local/jdk1.6.0/lib/tools.jar:/usr/local/pgsql/share/java/postgresql-8.1-408.jdbc3.jar:/usr/local/jdk1.6.0/lib/:/home/danish/:/home/danish/PostgreSQLTest.java > > > Thanks > Danish > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org >