Thread: JDBC Connection

JDBC Connection

From
Guido
Date:
Hi everybody, here's my poroblem:

Distibution - RH 7.1
JDK - 1.3.1


I try to connect to the pgsql data base with my application but all I get
it's the following exception
    java.lang.ClassNotFoundException: org.postgresql.Driver
which is thrown by
    Class.forName("org.postgresql.Driver");

I followed the instructions on the Programmer's Guide by exporting

    /usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar (the dir where I've put
the jdbc driver)

to my PATH.
When I echo the PATH I get the correct sequence.

Thanks for all the help you can give me.

Guido

Re: JDBC Connection

From
"Dave Cramer"
Date:
Guido,

Instead of adding it to PATH, you have to add it to an environment
variable CLASSPATH

Dave

-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Guido
Sent: November 8, 2001 3:15 PM
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] JDBC Connection


Hi everybody, here's my poroblem:

Distibution - RH 7.1
JDK - 1.3.1


I try to connect to the pgsql data base with my application but all I
get
it's the following exception
    java.lang.ClassNotFoundException: org.postgresql.Driver
which is thrown by
    Class.forName("org.postgresql.Driver");

I followed the instructions on the Programmer's Guide by exporting

    /usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar (the dir where I've
put
the jdbc driver)

to my PATH.
When I echo the PATH I get the correct sequence.

Thanks for all the help you can give me.

Guido


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster



Re: JDBC Connection

From
"Nick Fankhauser"
Date:
Guido-

> to my PATH.

Are you using PATH or CLASSPATH? It should be CLASSPTH.

Also, make sure you are executing the class from the same environment that
has classpath set. Sometimes people will compile in one environment & then
execute in another (for instance compiling in your development account &
then running from the Tomcat user if you're running servlets.)

regards,

-Nick

--------------------------------------------------------------------------
Nick Fankhauser  nickf@ontko.com  Phone 1.765.935.4283  Fax 1.765.962.9788
Ray Ontko & Co.     Software Consulting Services     http://www.ontko.com/


Re: JDBC Connection

From
"Nick Fankhauser"
Date:

> Are you using PATH or CLASSPATH? It should be CLASSPTH.
                                                 ^^^^^^
                                 oops! I meant CLASSPATH
                                          -NF



Re: JDBC Connection

From
Guido
Date:
First of all I'd like to thank everybody for the "pronto" help.
But the problem is that
1. My shell doesn't have an enviroment variable called CLASSPATH;
2. I, then, tried to edit my .profile file, by adding the variable to it,
i.e.
    CLASSPATH=/usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar
    export PATH CLASSPATH
   but, still doesn't work.
3. When I run the application in the Forte 3 enviroment, it works
perfectly, but that becuase the IDE requires to copy the driver to the
IDE's directory.
4. I use the same enviroment for developing and running the application.
Thanks again.

Re: JDBC Connection

From
"Dave Cramer"
Date:
Guido,

One way to get around the classpath issue is to put the jar into your
javahome/jre/lib/ext directory. By default all jars in this directory
will be accessible to your apps

So in your case there s/b a directory /usr/java/jdk1.3.1_01/jre/lib/ext

If you put the jar there it s/b available to your application

Dave

-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Guido
Sent: November 9, 2001 11:42 AM
To: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] JDBC Connection


First of all I'd like to thank everybody for the "pronto" help.
But the problem is that
1. My shell doesn't have an enviroment variable called CLASSPATH;
2. I, then, tried to edit my .profile file, by adding the variable to
it,
i.e.
    CLASSPATH=/usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar
    export PATH CLASSPATH
   but, still doesn't work.
3. When I run the application in the Forte 3 enviroment, it works
perfectly, but that becuase the IDE requires to copy the driver to the
IDE's directory.
4. I use the same enviroment for developing and running the application.
Thanks again.


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)



Re: JDBC Connection

From
"Nick Fankhauser"
Date:
Guido-

I probably didn't say this clearly enough, or perhaps "environment" is the
wrong word, so I'll try to explain what I meant with an example:

In the project I'm working on, we're using Tomcat, so I develop using my
user account, but run as Tomcat's user.

When I'm actually writing & compiling the code, I'm working from my own user
account (nickf), so in the .profile for nickf I add the path to the jdbc jar
like so: "export CLASSPATH=$CLASSPATH:/usr/share/java/jdbc7.1-1.2.jar". This
works great for compiling and running any "main" test classes at the command
line, but my purpose is to produce code that Tomcat will run, and therein
lies the twist...

The Tomcat processes are started as detached processes by the "www-data"
user account on our system, so the change that I made to the CLASSPATH
environment variable for "nickf" doesn't help. In order to make the classes
work under this user, I have to do one of three things:

1)Add the classpath line that I used for "nickf" to the .profile for
"www-data"

2)Add the jar file to the classpath in the shell script that starts up
Tomcat

3)As Dave suggested, put it in the standard java extensions directory for
the system, so it is available to any user account by default.

I may be totally off base here, but it sounds very much like this is the
problem that is plaguing you with Forte- If a different user account is
running the code after you get it out of Forte, then you may lose the
CLASSPATH that you set.

The other thing that may be happening is that the CLASSPATH variable may not
be used by your JRE. It might help to look under the hood at the shell
script that invokes the JRE to see what is happening- the command to invoke
the JRE has a switch to set the classpath on it, and by convention, most
systems just equate this to CLASSPATH, but they don't have to. See if you
can locate the shell file (or .bat file) that invokes your JRE- it should
have a line that looks something like this:

java -cp $CLASSPATH <class file>

The problem of course, would be if the "CLASSPATH" variable either isn't
being used, or is being changed before this line is run. The only way I can
thin of to check this would be to find the shell script in question. Maybe
if you tell us what platform you're running on, someone who is familiar with
it can help.

Sorry- this response got rather long-winded- Hope it helps.

-Nick



> -----Original Message-----
> From: pgsql-jdbc-owner@postgresql.org
> [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Guido
> Sent: Friday, November 09, 2001 11:42 AM
> To: pgsql-jdbc@postgresql.org
> Subject: Re: [JDBC] JDBC Connection
>
>
> First of all I'd like to thank everybody for the "pronto" help.
> But the problem is that
> 1. My shell doesn't have an enviroment variable called CLASSPATH;
> 2. I, then, tried to edit my .profile file, by adding the variable to it,
> i.e.
>     CLASSPATH=/usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar
>     export PATH CLASSPATH
>    but, still doesn't work.
> 3. When I run the application in the Forte 3 enviroment, it works
> perfectly, but that becuase the IDE requires to copy the driver to the
> IDE's directory.
> 4. I use the same enviroment for developing and running the application.
> Thanks again.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>


Re: JDBC Connection

From
"Max Larsson"
Date:
Hi,

if you want that Tomcat should find the jdbc jar you have two
places to it:

1.    $TOMCAT_HOME/lib or for TOMACT 4 $CATALINA_HOME/common/lib

or

2.    in your web application folder under WEB-INF/lib e.g if
    your web applictaion is anmed myapp :

    $TOMCAT_HOME/webapps/myapp/WEB-INF/lib or for Tomcat 4
    $CATALINA_HOME/webapps/myapp/WEB-INF/lib

HTH

Max

> -----Original Message-----
> From: pgsql-jdbc-owner@postgresql.org
> [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Nick Fankhauser
> Sent: Samstag, 10. November 2001 13:49
> To: Guido; pgsql-jdbc@postgresql.org
> Subject: Re: [JDBC] JDBC Connection
>
>
> Guido-
>
> I probably didn't say this clearly enough, or perhaps
> "environment" is the
> wrong word, so I'll try to explain what I meant with an example:
>
> In the project I'm working on, we're using Tomcat, so I
> develop using my
> user account, but run as Tomcat's user.
>
> When I'm actually writing & compiling the code, I'm working
> from my own user
> account (nickf), so in the .profile for nickf I add the path
> to the jdbc jar
> like so: "export
> CLASSPATH=$CLASSPATH:/usr/share/java/jdbc7.1-1.2.jar". This
> works great for compiling and running any "main" test classes
> at the command
> line, but my purpose is to produce code that Tomcat will run,
> and therein
> lies the twist...
>
> The Tomcat processes are started as detached processes by the
> "www-data"
> user account on our system, so the change that I made to the CLASSPATH
> environment variable for "nickf" doesn't help. In order to
> make the classes
> work under this user, I have to do one of three things:
>
> 1)Add the classpath line that I used for "nickf" to the .profile for
> "www-data"
>
> 2)Add the jar file to the classpath in the shell script that starts up
> Tomcat
>
> 3)As Dave suggested, put it in the standard java extensions
> directory for
> the system, so it is available to any user account by default.
>
> I may be totally off base here, but it sounds very much like
> this is the
> problem that is plaguing you with Forte- If a different user
> account is
> running the code after you get it out of Forte, then you may lose the
> CLASSPATH that you set.
>
> The other thing that may be happening is that the CLASSPATH
> variable may not
> be used by your JRE. It might help to look under the hood at the shell
> script that invokes the JRE to see what is happening- the
> command to invoke
> the JRE has a switch to set the classpath on it, and by
> convention, most
> systems just equate this to CLASSPATH, but they don't have
> to. See if you
> can locate the shell file (or .bat file) that invokes your
> JRE- it should
> have a line that looks something like this:
>
> java -cp $CLASSPATH <class file>
>
> The problem of course, would be if the "CLASSPATH" variable
> either isn't
> being used, or is being changed before this line is run. The
> only way I can
> thin of to check this would be to find the shell script in
> question. Maybe
> if you tell us what platform you're running on, someone who
> is familiar with
> it can help.
>
> Sorry- this response got rather long-winded- Hope it helps.
>
> -Nick
>
>
>
> > -----Original Message-----
> > From: pgsql-jdbc-owner@postgresql.org
> > [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Guido
> > Sent: Friday, November 09, 2001 11:42 AM
> > To: pgsql-jdbc@postgresql.org
> > Subject: Re: [JDBC] JDBC Connection
> >
> >
> > First of all I'd like to thank everybody for the "pronto" help.
> > But the problem is that
> > 1. My shell doesn't have an enviroment variable called CLASSPATH;
> > 2. I, then, tried to edit my .profile file, by adding the
> variable to it,
> > i.e.
> >     CLASSPATH=/usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar
> >     export PATH CLASSPATH
> >    but, still doesn't work.
> > 3. When I run the application in the Forte 3 enviroment, it works
> > perfectly, but that becuase the IDE requires to copy the
> driver to the
> > IDE's directory.
> > 4. I use the same enviroment for developing and running the
> application.
> > Thanks again.
> >
> >
> > ---------------------------(end of
> broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> >     (send "unregister YourEmailAddressHere" to
> majordomo@postgresql.org)
> >
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org