[TriLUG] dev question

William Sutton william at trilug.org
Thu Feb 19 03:56:38 EST 2004


Just for fun I'm working on an independent project to teach myself Java, 
including JDBC.  When I installed the system (Red Hat 9), I included 
PostgreSQL and the appropriate JDBC driver:

kenobi:~# rpm -qa |grep -i postgres
postgresql-libs-7.3.4-3.rhl9
postgresql-jdbc-7.3.4-3.rhl9
postgresql-odbc-7.2.5-1
postgresql-7.3.4-3.rhl9
postgresql-server-7.3.4-3.rhl9
postgresql72-libs-1-4.rhl9
postgresql-pl-7.3.4-3.rhl9

I have a sample snippet of Java code from the O'Reilly Practical 
PostgreSQL book:

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;

public class Example1
{
    public static void main(String[] argv)
    {
        System.out.println("Checking if driver is registered with DriveManager."
);

        try
        {
            Class.forName("org.postgresql.Driver");
        }
        catch(ClassNotFoundException cnfe)
        {
            System.out.println("Couldn't find the driver!");
            System.out.println("Printing stack trace.");
            cnfe.printStackTrace();
            System.exit(1);
        }

// etc, removed for brevity
}

The above code compiles to bytecode fine for me.  The trick is when I run 
it:

kenobi:~$ javac Example1.java 
kenobi:~$ java Example1
Checking if driver is registered with DriveManager.
Couldn't find the driver!
Printing stack trace.
java.lang.ClassNotFoundException: org.postgresql.Driver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:140)
        at Example1.main(Example1.java:13)

Any suggestions from either the Java gurus or the Red Hat folks as to why 
this is happening?

William Sutton




More information about the TriLUG mailing list