pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Can't get JDBC to compile. Please help.
3+ messages / 3 participants
[nested] [flat]

* Can't get JDBC to compile. Please help.
@ 2009-04-12 18:48  IronSheikh <kazisiddiqui@gmail.com>
  0 siblings, 2 replies; 3+ messages in thread

From: IronSheikh @ 2009-04-12 18:48 UTC (permalink / raw)
  To: pgsql-jdbc


I'm a beginner. I installed PostGRESQL 8.3 with edb_pgjdbc.exe on Windows XP
SP2.

The following test code won't compile:
package javaapplication1;
import java.sql.*;

public class Main {

    public static void main(String[] args) {
     try
     {
       helloPostgresql();
     }
     catch (Exception ex)
     {
       System.out.println("***Exception:\n"+ex);
       ex.printStackTrace();
     }
    }

    public static void helloPostgresql()
            throws ClassNotFoundException, SQLException
    {
     Class.forName("org.postgresql.Driver");
     Connection db = DriverManager.getConnection("jdbc:postgresql:pathos",
"postgres", "cuy4867z");

     PreparedStatement st = db.prepareStatement("INSERT INTO test VALUES
(?,?,?)");
     st.setInt(1, 5);
     st.setString(2, "'$10.00'");
     st.setString(3, "'full checkup'");
     st.executeUpdate();
     st.close();

     db.close();
    }

}

NetBeans says:
***Exception:
java.lang.ClassNotFoundException: org.postgresql.Driver
java.lang.ClassNotFoundException: org.postgresql.Driver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at javaapplication1.Main.helloPostgresql(Main.java:36)
        at javaapplication1.Main.main(Main.java:24)
BUILD SUCCESSFUL (total time: 0 seconds)

I've tried adding "E:\Program Files\PostgreSQL\pgJDBC" to the CLASSPATH. Any
suggestions?
-- 
View this message in context: http://www.nabble.com/Can%27t-get-JDBC-to-compile.-Please-help.-tp23013717p23013717.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Can't get JDBC to compile. Please help.
@ 2009-04-13 15:34  Dave Cramer <pg@fastcrypt.com>
  parent: IronSheikh <kazisiddiqui@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Dave Cramer @ 2009-04-13 15:34 UTC (permalink / raw)
  To: IronSheikh <kazisiddiqui@gmail.com>; +Cc: pgsql-jdbc

You have to add the actual postgresql jar file to the classpath.

Dave

On Sun, Apr 12, 2009 at 2:48 PM, IronSheikh <kazisiddiqui@gmail.com> wrote:

>
> I'm a beginner. I installed PostGRESQL 8.3 with edb_pgjdbc.exe on Windows
> XP
> SP2.
>
> The following test code won't compile:
> package javaapplication1;
> import java.sql.*;
>
> public class Main {
>
>    public static void main(String[] args) {
>     try
>     {
>       helloPostgresql();
>     }
>     catch (Exception ex)
>     {
>       System.out.println("***Exception:\n"+ex);
>       ex.printStackTrace();
>     }
>    }
>
>    public static void helloPostgresql()
>            throws ClassNotFoundException, SQLException
>    {
>     Class.forName("org.postgresql.Driver");
>     Connection db = DriverManager.getConnection("jdbc:postgresql:pathos",
> "postgres", "cuy4867z");
>
>     PreparedStatement st = db.prepareStatement("INSERT INTO test VALUES
> (?,?,?)");
>     st.setInt(1, 5);
>     st.setString(2, "'$10.00'");
>     st.setString(3, "'full checkup'");
>     st.executeUpdate();
>     st.close();
>
>     db.close();
>    }
>
> }
>
> NetBeans says:
> ***Exception:
> java.lang.ClassNotFoundException: org.postgresql.Driver
> java.lang.ClassNotFoundException: org.postgresql.Driver
>        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
>        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
>        at java.lang.Class.forName0(Native Method)
>        at java.lang.Class.forName(Class.java:169)
>        at javaapplication1.Main.helloPostgresql(Main.java:36)
>        at javaapplication1.Main.main(Main.java:24)
> BUILD SUCCESSFUL (total time: 0 seconds)
>
> I've tried adding "E:\Program Files\PostgreSQL\pgJDBC" to the CLASSPATH.
> Any
> suggestions?
> --
> View this message in context:
> http://www.nabble.com/Can%27t-get-JDBC-to-compile.-Please-help.-tp23013717p23013717.html
> Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Can't get JDBC to compile. Please help.
@ 2009-04-13 17:51  Guy Rouillier <guyr-ml1@burntmail.com>
  parent: IronSheikh <kazisiddiqui@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Guy Rouillier @ 2009-04-13 17:51 UTC (permalink / raw)
  To: pgsql-jdbc

IronSheikh wrote:
> I'm a beginner. I installed PostGRESQL 8.3 with edb_pgjdbc.exe on Windows XP
> SP2.
> 
> The following test code won't compile:

> NetBeans says:
> ***Exception:
> java.lang.ClassNotFoundException: org.postgresql.Driver

> I've tried adding "E:\Program Files\PostgreSQL\pgJDBC" to the CLASSPATH. Any
> suggestions?

The error message is pretty clear - it can't find the driver.  You don't 
add the entire directory to your classpath - just the JAR file 
containing the JDBC driver.

-- 
Guy Rouillier



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2009-04-13 17:51 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-04-12 18:48 Can't get JDBC to compile. Please help. IronSheikh <kazisiddiqui@gmail.com>
2009-04-13 15:34 ` Dave Cramer <pg@fastcrypt.com>
2009-04-13 17:51 ` Guy Rouillier <guyr-ml1@burntmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox