Thread: org.postgresql.Driver

org.postgresql.Driver

From
Bernardo López
Date:
Greetings!
I am starting to learn Java, and starting to use PostGreSQL too.
I need some major help here.
I am working under Windows XP Home Edition, and working with:

PostgreSQL 8.0.
pgAdmin III, v. 1.2.2.
jdk1.5.0_04.
JCreator 3.50 LE.

I am trying to run this example:

// File Connect.java
// Code starts here.
import java.sql.*;
public class Connect {
  public static void main(String[] args) {
    Connection cnn;
    try {
    Class.forName("org.postgresql.Driver");
    cnn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/","postgres","");
    Statement stmt = cnn.createStatement();
    int login=1;
    ResultSet rs = stmt.executeQuery("select * from usuarios");
    if (rs!=null) {
        while (rs.next()) {
            System.out.println(rs.getString("login"));
            System.out.println(rs.getString("password"));
            System.out.println(rs.getString("nombre"));
        }
    }
          rs.close();
        stmt.close();
        cnn.close();
    } catch (Exception e) {
    System.out.println(e);
    }

  }
}
// Code ends here.

But I keep getting the error message:

java.lang.ClassNotFoundException: org.postgresql.Driver

I've read a couple of related messages in this and other forums, but
nothing yet.
After many attempts, my PATH, CLASSPATH and other environment
variables are set like this:

- - - -
PATH
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%JAVA_HOME%\bin
- - - -
JAVA_HOME
C:\Archivos de programa\Java\jdk1.5.0_04
- - - -
CLASSPATH
%JAVA_HOME%\jre\lib;"C:\Archivos de
programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2.jar";"C:\Archivos
de programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2ee.jar";"C:\Archivos
de programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc3.jar"
- - - -
QTJAVA
"C:\Archivos de programa\Java\jre1.5.0_04\QTJava.zip"
- - - -

All help will be appreciated!

Keep posting!

Re: org.postgresql.Driver

From
Bernardo López
Date:
Thanks for the prompt answer Aaron!
Unfortunately it's still not working :S
The System.getProperty("java.class.path") returns the folder the file
is in and other folders:

C:\UNIV 2005-1\Labs\Lab 20051018;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\rt.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\lib\dt.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\lib\tools.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\dnsns.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\localedata.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\sunjce_provider.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\sunpkcs11.jar

Also set the PATH and others without the " marks.
I'll take a look to the FAQ page.
I'll keep trying.

Thanks for all!, and keep posting!

ßernardo L.

Re: org.postgresql.Driver

From
"Announce"
Date:
Hey Bernardo,

I'm a PG rookie but I DO know Java. Your PATH env variable doesn't need to
include the JDBC .jar but your CLASSPATH definitely does need to include the
appropriate .jar file.  You could verify that your environment knows about
he jar file by doing something like:

    System.out.println(System.getProperty("java.class.path"));

At the top of the main method.

Sometimes I make a mistake of misspelling a the path to that file or another
one. If you see that jar file in the System.out output, you know that it's
setting up your classpath ok.  You can verify spelling by copy/pasting part
of the java.class.path output into the dos prompt and doing something like:

dir "C:\Archivos de
programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2ee.jar"

It should find the file specified.  I can also tell you that on my WinXP Pro
install, I do not need to include the quotation marks (") around the path
names.  I'm thinking that this is causing a problem. So

%JAVA_HOME%\jre\lib;"C:\Archivos de
programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2.jar";"C:\Archivos
de programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2ee.jar";"C:\Archivos
de programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc3.jar"

would become:

%JAVA_HOME%\jre\lib;C:\Archivos de
programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2.jar;C:\Archivos
de programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2ee.jar;C:\Archivos
de programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc3.jar

without the carriage returns.

Give that a try.

-Aaron
-----Original Message-----
From: pgsql-novice-owner@postgresql.org
[mailto:pgsql-novice-owner@postgresql.org]On Behalf Of Bernardo López
Sent: Thursday, November 17, 2005 8:51 PM
To: pgsql-novice@postgresql.org
Subject: [NOVICE] org.postgresql.Driver


Greetings!
I am starting to learn Java, and starting to use PostGreSQL too.
I need some major help here.
I am working under Windows XP Home Edition, and working with:

PostgreSQL 8.0.
pgAdmin III, v. 1.2.2.
jdk1.5.0_04.
JCreator 3.50 LE.

I am trying to run this example:

// File Connect.java
// Code starts here.
import java.sql.*;
public class Connect {
  public static void main(String[] args) {
    Connection cnn;
    try {
    Class.forName("org.postgresql.Driver");
    cnn =
DriverManager.getConnection("jdbc:postgresql://localhost:5432/","postgres","
");
    Statement stmt = cnn.createStatement();
    int login=1;
    ResultSet rs = stmt.executeQuery("select * from usuarios");
    if (rs!=null) {
        while (rs.next()) {
            System.out.println(rs.getString("login"));
            System.out.println(rs.getString("password"));
            System.out.println(rs.getString("nombre"));
        }
    }
          rs.close();
        stmt.close();
        cnn.close();
    } catch (Exception e) {
    System.out.println(e);
    }

  }
}
// Code ends here.

But I keep getting the error message:

java.lang.ClassNotFoundException: org.postgresql.Driver

I've read a couple of related messages in this and other forums, but
nothing yet.
After many attempts, my PATH, CLASSPATH and other environment
variables are set like this:

- - - -
PATH
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%JAVA_HOME%\bi
n
- - - -
JAVA_HOME
C:\Archivos de programa\Java\jdk1.5.0_04
- - - -
CLASSPATH
%JAVA_HOME%\jre\lib;"C:\Archivos de
programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2.jar";"C:\Archivos
de programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2ee.jar";"C:\Archivos
de programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc3.jar"
- - - -
QTJAVA
"C:\Archivos de programa\Java\jre1.5.0_04\QTJava.zip"
- - - -

All help will be appreciated!

Keep posting!

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.3/173 - Release Date: 11/16/2005


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.3/173 - Release Date: 11/16/2005


Re: org.postgresql.Driver

From
"Announce"
Date:
Ok. If I'm understanding you correctly then your JDBC .jars ARE NOT in the
CLASSPATH then.
The fact that your java.class.path output looks so different from what you
sent in the initial email means that you are executing that Connect program
in a completely different environment or under a different user.

Perhaps you are running this application in an IDE (such as Eclipse) or on a
servlet (probably not because of the MAIN method you are using)? This would
explain the difference in CLASSPATH output. How ARE you determining what
your CLASSPATH is? Are you using any tools, IDEs to run this program?

You should see a fully qualified path to all of the postgresql-*jdbc*.jar
files you included, not just the DIRECTORY they exist in.  For example:

C:\UNIV 2005-1\Labs\Lab 20051018;
C:\Archivos de programa\PostgreSQL\8.0\jdbc\;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\rt.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\lib\dt.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\lib\tools.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\dnsns.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\localedata.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\sunjce_provider.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\sunpkcs11.jar

Is not going to work because you've only specified the DIRECTORY and not the
full FILE PATH that includes the '.jar' name.

But:

.;C:\UNIV 2005-1\Labs\Lab 20051018;
C:\Archivos de programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2.jar;
C:\Archivos de programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2ee.jar;
C:\Archivos de programa\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc3.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\rt.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\lib\dt.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\lib\tools.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\dnsns.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\localedata.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\sunjce_provider.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\sunpkcs11.jar

Should work because you provided the full file spec. There should be no line
breaks or spaces next to the semi colons (;).  Also note that I included
".;" and the JDBC .jars at the BEGINNING of the CLASSPATH.

-Aaron

-----Original Message-----
From: pgsql-novice-owner@postgresql.org
[mailto:pgsql-novice-owner@postgresql.org]On Behalf Of Bernardo López
Sent: Thursday, November 17, 2005 10:46 PM
To: pgsql-novice@postgresql.org
Subject: Re: [NOVICE] org.postgresql.Driver


Thanks for the prompt answer Aaron!
Unfortunately it's still not working :S
The System.getProperty("java.class.path") returns the folder the file
is in and other folders:

C:\UNIV 2005-1\Labs\Lab 20051018;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\rt.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\lib\dt.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\lib\tools.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\dnsns.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\localedata.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\sunjce_provider.jar;
C:\Archivos de programa\Java\jdk1.5.0_04\jre\lib\ext\sunpkcs11.jar

Also set the PATH and others without the " marks.
I'll take a look to the FAQ page.
I'll keep trying.

Thanks for all!, and keep posting!

ßernardo L.


Re: org.postgresql.Driver

From
Bernardo López
Date:
Well, I uninstalled and then installed everything related to the
problem, and now it's working.
I set everything this way:

CLASSPATH
.\;
C:\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc3.jar;
C:\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2ee.jar;
C:\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2.jar;
C:\Java\jdk1.5.0_04\jre\lib\rt.jar;
C:\Java\jdk1.5.0_04\lib\dt.jar;
C:\Java\jdk1.5.0_04\lib\tools.jar

PATH
%SystemRoot%\system32;
%SystemRoot%;
%SystemRoot%\System32\Wbem;
C:\Java\jdk1.5.0_04\bin

JCreator > Configure > Options > JDK Profiles:
Name:
JDK 1.5.0_04 + PostGreSQL 8.0
Home path:
C:\Java\jdk1.5.0_04\
Default classpath of the selected JDK profile:
C:\Java\jdk1.5.0_04\jre\lib\rt.jar;
C:\Java\jdk1.5.0_04\lib\dt.jar;
C:\Java\jdk1.5.0_04\lib\tools.jar;
C:\Java\jdk1.5.0_04\jre\lib\ext\dnsns.jar;
C:\Java\jdk1.5.0_04\jre\lib\ext\localedata.jar;
C:\Java\jdk1.5.0_04\jre\lib\ext\sunjce_provider.jar;
C:\Java\jdk1.5.0_04\jre\lib\ext\sunpkcs11.jar;
C:\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc3.jar;
C:\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2ee.jar;
C:\PostgreSQL\8.0\jdbc\postgresql-8.0-311.jdbc2.jar

With neither breaks nor spaces next to the ;

Thanks for the help!

ßernardo L.

On 11/18/05, Announce <truthhurts@insightbb.com> wrote:
> -----Original Message-----
> From: pgsql-novice-owner@postgresql.org
> [mailto:pgsql-novice-owner@postgresql.org]On Behalf Of Bernardo López
> Sent: Thursday, November 17, 2005 10:46 PM
> To: pgsql-novice@postgresql.org
> Subject: Re: [NOVICE] org.postgresql.Driver