java + debian + postgresql

hey all!!!

i ve got a problem with connecting postresql on debian with (to) java application. this problem is quite common (i have done my research on the internet) and there is a lot about it on the net but i just don't seem to be able to resolve this.

anyway

os = debian sarge

java =

nikdo@debil:~/java/postres$ java -version

java version "1.5.0_10"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)

Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode, sharing)

postgres =

nikdo@debil:~/java/postres$ psql --version

psql (PostgreSQL) 7.4.7

contains support for command-line editing

i have downloaded postgresql-8.0-319.jdbc3.jar postgresql-8.1-409.jdbc3.jar postgresql-8.2-505.jdbc3.jar and have tried to use them one by one (from 8.2 to 8.0) and nothing

so then i downloaded the source of the driver (via cvs) and compiled it into postgresql.jar and tried again and again nothing.

so i looked on the internet and found all the $CLASSPATH vars and so (actually i already knew about those due to the first build failure) and set those, tried my luck number of times and nothing so i unset them again and tried with javac -cp <path to the file> and have made sure that it is the whole path (the *.jar file included) and again nothing. so i have tried

java -Djdbc.drivers=org.postgresql.Driver neco.javaoption when compiling and again nothing. well simply i don't know what else to do. if anyone can help me.... i would really appreciate that!!!!

the only lead i have got is this...

code:

import java.sql.*;

public class neco{

public static void main(String[] vik){

try{

Class.forName("org.postgresql.Driver");

System.out.println("ok");

}catch(ClassNotFoundException cnfe){

System.out.println("no good");

//cnfe.printStackTrace();

}

}

}

when i compile like

javac neco.java = then no error

when run

java neco = then it throws the exception text 'no good'

when i compile like

javac -cp <path to *.jar file> neco.java = no error

when run

java -cp <path to *.jar file> neco = then no exception text but 'Exception in thread "main" java.lang.NoClassDefFoundError: neco'

that i suppose is quite the same thing but it confuses me why it gives 2 different types of error text.

well that's about all

thanks

vella

[2516 byte] By [velladecina] at [2007-11-27 8:05:55]
# 1

> java -cp <path to *.jar file> neco = then no exception text

> but 'Exception in thread "main" java.lang.NoClassDefFoundError: neco'

It's telling you it can't find the class called neco, which in turn implies that it can't find the file neco.class

Since your neco.class file has only just been compiled, I presume you haven't put it into a jar file. Therefore it's not in the classpath - you'll need to add the current working directory (a single period indicates this) assuming that the file is in your working directory, or alternatively a full explicit path to the directory containing neco.class.

It's conventional to give classes names beginning with a capital letter by the way.

dcmintera at 2007-7-12 19:48:25 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

hey dcminter!!

i'm just in the middle of exam period so i didn't have time to check this forum straight away....

well i have just tried

javac -cp ./<path to *.jar file>:. neco.java

... and no error and then

java -cp ./<path to *.jar file>:. neco

.. and everything is ok.... ((:

so basically i have added the .jar file to my current working directory and added that little colon and a dot ":." at the end of the path and that was the problem as you have suggested... thanks a lot!!!!!!

by the way i'm very lazy that's why no capital letters with classes (:

vella

velladecina at 2007-7-12 19:48:25 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

> hey dcminter!!

>

> i'm just in the middle of exam period so i didn't

> have time to check this forum straight away....

>

> well i have just tried

> javac -cp ./<path to *.jar file>:. neco.java

Here it's unnecessary - that's a file, not a class, that you're compiling, so you provide the path to the file. If it's in your working directory it's in your path. You do need a classpath, but only so that the compiler can find the classes that it hasn't been told to compile.

> by the way i'm very lazy that's why no capital

> letters with classes (:

I'm very lazy, that's why I use the capital letter convention to distinguish between variables and Classes without having to go and look to see where they're declared.

dcmintera at 2007-7-12 19:48:25 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
hey dcminter!like before you were rigth ((:... and with the laziness.... i can see your point, but until i start to write smth more complex i won't press that shift hehe and will save my little finger for my q,a,z's\thanks againv.d.
velladecina at 2007-7-12 19:48:25 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...