Обсуждение: getting JDBC connection working

Поиск
Список
Период
Сортировка

getting JDBC connection working

От
"Iain"
Дата:
Hi All,
 
This is hopefully a quick question.
 
Do I need to re-build the postgres installation using the --with-java option in order to use JDBC? I got the JDBC driver and set the CLASSPATH as per the docs, but I wasn't clear on whether the --with-java option is still required given that I downloaded a pre-built driver.
 
My little test program is currently failing with a ClassNotFoundException during the call:
 
Class.forName("org.postgresql.Driver");
 
Thanks in advance,
Iain

Re: getting JDBC connection working

От
Kris Jurka
Дата:

On Tue, 13 Jan 2004, Iain wrote:

> Hi All,
>
> This is hopefully a quick question.
>
> Do I need to re-build the postgres installation using the --with-java option
> in order to use JDBC? I got the JDBC driver and set the CLASSPATH as per the
> docs, but I wasn't clear on whether the --with-java option is still required
> given that I downloaded a pre-built driver.

The --with-java option is only if you want to build the driver yourself.
 If you've downloaded a prebuilt binary there is no need for this.

> My little test program is currently failing with a ClassNotFoundException
> during the call:
>
> Class.forName("org.postgresql.Driver");
>

You have apparently not set the classpath correctly.

Kris Jurka



Re: getting JDBC connection working

От
"Iain"
Дата:
Hi Kris,

Thanks for your help.

> The --with-java option is only if you want to build the driver yourself.
>  If you've downloaded a prebuilt binary there is no need for this.

OK, that makes sense.

> > My little test program is currently failing with a
ClassNotFoundException
> > during the call:
> >
> > Class.forName("org.postgresql.Driver");
>
> You have apparently not set the classpath correctly.

typing "env" from the postgres user account, gives the following:

CLASSPATH=/usr/local/pgsql/share/java/pg74jdbc3.jar:.

I double checked and the file is in that directory. I stopped and resterted
the DB too.

This is my first time to use Java, so I may be missing something obvious.
All I have done so far is put in the JDBC driver as I described, and
download the windows version of the Java IDE and test a small program to
connect. As far as I know there is no JVM on the server at he moment. TCP/IP
connections are enabled, and working OK for ODBC apps.

If you have any more ideas, please let me know,
regards
Iain
>
> Kris Jurka
>


Re: getting JDBC connection working

От
Kris Jurka
Дата:

On Tue, 13 Jan 2004, Iain wrote:

> typing "env" from the postgres user account, gives the following:
>
> CLASSPATH=/usr/local/pgsql/share/java/pg74jdbc3.jar:.
>
> I double checked and the file is in that directory. I stopped and resterted
> the DB too.
>
> This is my first time to use Java, so I may be missing something obvious.
> All I have done so far is put in the JDBC driver as I described, and
> download the windows version of the Java IDE and test a small program to
> connect. As far as I know there is no JVM on the server at he moment. TCP/IP
> connections are enabled, and working OK for ODBC apps.
>

You've got things all backwards.  The jar file is unnecessary on the
database server (unless you want to establish a connection from the
server machine).  It is a client access library and in this case should be
on your windows machine.  That's step one.  Step two is that often IDEs
override the CLASSPATH environment variable and you will probably need to
figure out how to add the jar file to your IDE.

Kris Jurka


Re: getting JDBC connection working

От
"Iain"
Дата:
> You've got things all backwards.  The jar file is unnecessary on the
> database server (unless you want to establish a connection from the
> server machine).  It is a client access library and in this case should be
> on your windows machine.  That's step one.

You were pretty much right there. I will be needing this app to run on the
server too, but that'a a little later down the track.

>  Step two is that often IDEs
> override the CLASSPATH environment variable and you will probably need to
> figure out how to add the jar file to your IDE.

Right again. I finally got it - I'm using netbeans3.51, and I stuffed the
.jar file in the same directory as my app (this isn't actually needed I
gather) and used the "Mount File System" to mount the project directory and
then I mounted the .jar file as an archive. That did it, and I'm connected
now.

Thanks again for your help.

Iain