Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 03AD89FB3DD for ; Fri, 22 Jun 2007 16:40:38 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 88406-02 for ; Fri, 22 Jun 2007 16:40:32 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.182]) by postgresql.org (Postfix) with ESMTP id 0BE1E9FB57B for ; Fri, 22 Jun 2007 16:40:31 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id k40so973456wah for ; Fri, 22 Jun 2007 12:40:30 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; b=PemwY+fqpGlR8TWGKn89vWImqSGFNGRoduHIZuAx6G5xrigVRF/NMR14aPmPXl8gjMQIZYd9FOJ9berehBTHDgjvKoUpVXH8/iFQtn6D+uWH9YqLV+GStzh+zuV6GURzcRk6VuNZKos05/mCNfV4N2wg0vRndAdjjngE4psKmHM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=DIu7EjIP+fI23UnWFPmroSv0i9aCTnqYAZD33C8fYeC9t+aL4vWG+PpgEmMj7qozowknPQaltUaWxaB9D+Phbr5L8MYwQoMPTQe3htygA/iuMwYhQeaM2Jx/7fnAUo1aPoAnHYyI7TsC9LM1gBSXG6BXoX9pT1K3EtF2HjHktYU= Received: by 10.114.13.1 with SMTP id 1mr3217035wam.1182541230653; Fri, 22 Jun 2007 12:40:30 -0700 (PDT) Received: by 10.114.112.17 with HTTP; Fri, 22 Jun 2007 12:40:30 -0700 (PDT) Message-ID: Date: Fri, 22 Jun 2007 22:40:30 +0300 From: "Kareem Habib" To: pgsql-jdbc@postgresql.org Subject: Unable to compile java file with all Classpaths set MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_103296_7838349.1182541230628" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/75 X-Sequence-Number: 17137 ------=_Part_103296_7838349.1182541230628 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline I'm in a bit of a dilemma. I need to connect to a PostgreSQL database through JAVA and so naturally I checked out the JDBC drivers. I downloaded the JDBC 3 driver (both 8.2 and the 8.3dev) as I am using JDK 1.5. I set the CLASSPATH in the environment variables to C:\postgresql.jar (I renamed the one i was using to this). I then wrote a test file that will make sure that I've set up everything correctly. I found this sample on the net so I decided to use it... I only wanted it to compile, nothing more. import java.sql.*; public class maxi{ public static void main(String[] args){ Class.forName("org.postgresql.Driver"); String url = "jdbc:postgresql://server8.cs.uofs.edu/"; String dbname = "uofsis"; String usernm = "bi"; String passwd = ""; Connection db = DriverManager.getConnection(url+dbname, usernm, passwd); Statement st = db.createStatement(); String sql = "SELECT name, title " + "FROM faculty f, course c " + "WHERE f.id = c.instructor"; ResultSet rs = st.executeQuery(sql); st.close(); db.close(); } } Every time I compile it I get the following output: C:\>javac maxi.java maxi.java:5: unreported exception java.lang.ClassNotFoundException; must be caug ht or declared to be thrown Class.forName("org.postgresql.Driver"); ^ maxi.java:11: unreported exception java.sql.SQLException; must be caught or decl ared to be thrown Connection db = DriverManager.getConnection(url+dbname, usernm, pass wd); ^ maxi.java:13: unreported exception java.sql.SQLException; must be caught or decl ared to be thrown Statement st = db.createStatement(); ^ maxi.java:16: unreported exception java.sql.SQLException; must be caught or decl ared to be thrown ResultSet rs = st.executeQuery(sql); ^ maxi.java:18: unreported exception java.sql.SQLException; must be caught or decl ared to be thrown st.close(); ^ maxi.java:19: unreported exception java.sql.SQLException; must be caught or decl ared to be thrown db.close(); ^ 6 errors I've tried versions 1.5 and 1.6 of the JDK on Windows XP, Windows Vista, and Ubuntu Linux using JDBC 3 and JDBC 4 drivers for 8.0, 8.2, and 8.3dev and they all output the same errors. I also tried writing it using NetBeans and importing the jar file into its libraries for the test project I created. The same errors appeared. What am I missing here?? Perhaps somebody can help. Thanks Kareem ------=_Part_103296_7838349.1182541230628 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I'm in a bit of a dilemma. I need to connect to a PostgreSQL database through JAVA and so naturally I checked out the JDBC drivers. I downloaded the JDBC 3 driver (both 8.2 and the 8.3dev) as I am using JDK 1.5. I set the CLASSPATH in the environment variables to C:\postgresql.jar (I renamed the one i was using to this). I then wrote a test file that will make sure that I've set up everything correctly. I found this sample on the net so I decided to use it... I only wanted it to compile, nothing more.

import java.sql.*;

public class maxi{
    public static void main(String[] args){
        Class.forName("org.postgresql.Driver");

        String url = "jdbc:postgresql://server8.cs.uofs.edu/";
        String dbname = "uofsis";
        String usernm = "bi";
        String passwd = "";
        Connection db = DriverManager.getConnection(url+dbname, usernm, passwd);

        Statement st = db.createStatement();

        String sql = "SELECT name, title " + "FROM faculty f, course c " + "WHERE f.id = c.instructor";
        ResultSet rs = st.executeQuery(sql);

        st.close();
        db.close();
        }
    }

Every time I compile it I get the following output:

C:\>javac maxi.java
maxi.java:5: unreported exception java.lang.ClassNotFoundException; must be caug
ht or declared to be thrown
                Class.forName("org.postgresql.Driver");
                             ^
maxi.java:11: unreported exception java.sql.SQLException; must be caught or decl
ared to be thrown
            Connection db = DriverManager.getConnection (url+dbname, usernm, pass
wd);
                                                       ^
maxi.java:13: unreported exception java.sql.SQLException; must be caught or decl
ared to be thrown
            Statement st = db.createStatement();
                                             ^
maxi.java:16: unreported exception java.sql.SQLException; must be caught or decl
ared to be thrown
            ResultSet rs = st.executeQuery(sql);
                                          ^
maxi.java:18: unreported exception java.sql.SQLException; must be caught or decl
ared to be thrown
            st.close();
                    ^
maxi.java:19: unreported exception java.sql.SQLException; must be caught or decl
ared to be thrown
            db.close();
                    ^
6 errors

I've tried versions 1.5 and 1.6 of the JDK on Windows XP, Windows Vista, and Ubuntu Linux using JDBC 3 and JDBC 4 drivers for 8.0, 8.2, and 8.3dev and they all output the same errors. I also tried writing it using NetBeans and importing the jar file into its libraries for the test project I created. The same errors appeared. What am I missing here?? Perhaps somebody can help.

Thanks
Kareem
------=_Part_103296_7838349.1182541230628--