Newbie - problem accessing DB2 with Java program.

Z

zalek

In my installation we have DB2 on a mainframe computer. I am able to
access DB2 from my PC (WinXP) using some utilities. I wrote a Java
program to access DB2, but I am getting errors.
After command:
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

I am getting exception:
Exception java.lang.ClassNotFoundException:
COM.ibm.db2.jdbc.app.DB2Driver

I copied db2java.zip and db2jcc.jar files to a default directory of
JBuilder, even to the same directory where I have my program, but it
did not help.
What I am doing wrong?

Thanks,

Zalek
 
A

Arne Vajhøj

zalek said:
In my installation we have DB2 on a mainframe computer. I am able to
access DB2 from my PC (WinXP) using some utilities. I wrote a Java
program to access DB2, but I am getting errors.
After command:
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

I am getting exception:
Exception java.lang.ClassNotFoundException:
COM.ibm.db2.jdbc.app.DB2Driver

I copied db2java.zip and db2jcc.jar files to a default directory of
JBuilder, even to the same directory where I have my program, but it
did not help.
What I am doing wrong?

You need to put the JDBC driver jar file in classpath. Just putting
then in those directories does not put them in classpath.

Arne
 
Z

zalek

You need to put the JDBC driver jar file in classpath. Just putting
then in those directories does not put them in classpath.

Arne

I tried - it did not help.
I am using JBuilder to write my program, so I moved db2java.zip and
db2jcc.jar to
C:\JBuilder2005\jdk1.4\bin and
C:\JBuilder2005\jdk1.4\lib

On top of it I found a directory in a classpath variable and move this
files to this directory - nothing helped. Still getting the same
error.

Zalek
 
A

Arne Vajhøj

zalek said:
I tried - it did not help.
I am using JBuilder to write my program, so I moved db2java.zip and
db2jcc.jar to
C:\JBuilder2005\jdk1.4\bin and
C:\JBuilder2005\jdk1.4\lib

On top of it I found a directory in a classpath variable and move this
files to this directory - nothing helped. Still getting the same
error.

I repeat:

Just putting a jar file in a directory does not put it in classpath.

(with a few exceptions that does not apply here)

You need explicitly to tell JBuilder to use this jar file.

Arne
 
Z

zalek

I repeat:

Just putting a jar file in a directory does not put it in classpath.

(with a few exceptions that does not apply here)

You need explicitly to tell JBuilder to use this jar file.

Arne

Thanks Arne,

I added files to JBuilder classpath, so now the import command is
working and it shows DB2Driver, here is a picture from my program:
http://www.geocities.com/bloomzalek/pictures/java.JPG
but still I am getting:
Exception java.lang.ClassNotFoundException:
COM.ibm.db2.jdbc.net.DB2Driver

Thanks,

Zalek
 
A

Alex.From.Ohio.Java

Thanks Arne,

I added files to JBuilder classpath, so now the import command is
working and it shows DB2Driver, here is a picture from my program:http://www.geocities.com/bloomzalek/pictures/java.JPG
but still I am getting:
Exception java.lang.ClassNotFoundException:
COM.ibm.db2.jdbc.net.DB2Driver

Thanks,

Zalek

Another very nice way to use classes (actually jar files) without
touching classpath is to put these jar files to the $JAVA_HOME/jre/lib/
ext/ directory.
For example, in my case, when I put db2java.zip and
db2jcc.jar to the
"C:\Program Files\Java\jre1.6.0_03\lib\ext\"
it is available for any Java application.

Just make sure that you put these jar files to the Java what you use!
Or put it to the all Java installations on your computer if you are
not sure which one you use ;)

Alex.
http://www.myjavaserver.com/~alexfromohio/

http://www.myjavaserver.com/~alexfromohio/
 
L

Lew

Another very nice way to use classes (actually jar files) without
touching classpath is to put these jar files to the $JAVA_HOME/jre/lib/
ext/ directory.

You mean a very *bad* way to use JAR files is to put them there.

It is also useless for those writing software to deploy elsewhere - for those
folks it is necessary to master deployment with classpaths specific to the
application.

Java extension directories are a way to customize the Java platform, not
suitable for creating application classpaths. At least, not for JVMs that are
going to run more than one application with different library requirements.
 
Z

zalek

Another very nice way to use classes (actually jar files) without
touching classpath is to put these jar files to the $JAVA_HOME/jre/lib/
ext/ directory.
For example, in my case, when I put db2java.zip and
db2jcc.jar to the
"C:\Program Files\Java\jre1.6.0_03\lib\ext\"
it is available for any Java application.

Just make sure that you put these jar files to the Java what you use!
Or put it to the all Java installations on your computer if you are
not sure which one you use ;)

Alex.http://www.myjavaserver.com/~alexfromohio/

http://www.myjavaserver.com/~alexfromohio/

Alex,

This is what I don't understand. Import command shows that the package
COM.ibm.db2.jdbc.net.DB2Driver is available - it shows also it
includes DB2Driver class. So why I am getting a message class not
found?

Zalek
 
A

Arne Vajhøj

zalek said:
I added files to JBuilder classpath, so now the import command is
working and it shows DB2Driver, here is a picture from my program:
http://www.geocities.com/bloomzalek/pictures/java.JPG
but still I am getting:
Exception java.lang.ClassNotFoundException:
COM.ibm.db2.jdbc.net.DB2Driver

Exactly where did you add it to classpath ?

You seems to be using JBuilder classis (non-Eclipse based).

You add it in:
project
project properties
required libraries
add
...

Arne
 
A

Arne Vajhøj

Another very nice way to use classes (actually jar files) without
touching classpath is to put these jar files to the $JAVA_HOME/jre/lib/
ext/ directory.
For example, in my case, when I put db2java.zip and
db2jcc.jar to the
"C:\Program Files\Java\jre1.6.0_03\lib\ext\"
it is available for any Java application.

Just make sure that you put these jar files to the Java what you use!
Or put it to the all Java installations on your computer if you are
not sure which one you use ;)

Very bad way.

Builds will break when Java is updated.

It does not work with multiple versions of the same software.

Etc..

Arne
 
R

RedGrittyBrick

zalek said:
In my installation we have DB2 on a mainframe computer. I am able to
access DB2 from my PC (WinXP) using some utilities. I wrote a Java
program to access DB2, but I am getting errors.
After command:
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

I am getting exception:
Exception java.lang.ClassNotFoundException:
COM.ibm.db2.jdbc.app.DB2Driver


Case matters, I've not used DB2 but are you certain the COM is capitalised?

I'd expect
com.ibm.db2.jdbc.app.DB2Driver
instead of
COM.ibm.db2.jdbc.app.DB2Driver


Also, you are cross-posting to four newsgroups, a lot of people will
have their newsreaders configured to treat highly cross-posted messages
as SPAM and ignore them. IME it is better to pick one newsgroup.

Followups set to c.l.j.d only.
 
Z

zalek

Very bad way.

Builds will break when Java is updated.

It does not work with multiple versions of the same software.

Etc..

Arne

Guys,

Thanks to all for your help - Arne was 100% right - it is my fault.
After receiving class not found conditions I copied db2java.zip and
db2jcc.jar to any possible directory - it does not help. I removed
these files, put to only 1 directory and using "properties" in
JBuilder I added pointed to this directory - and now my Java program
is working.
Thanks again!

Zalek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top