Unix Technical Forum

Newbie - problem accessing DB2 with Java program.

This is a discussion on Newbie - problem accessing DB2 with Java program. within the DB2 forums, part of the Database Server Software category; --> In my installation we have DB2 on a mainframe computer. I am able to access DB2 from my PC ...


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-17-2008, 06:12 AM
zalek
 
Posts: n/a
Default Newbie - problem accessing DB2 with Java program.

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-17-2008, 06:12 AM
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
 
Posts: n/a
Default Re: Newbie - problem accessing DB2 with Java program.

zalek wrote:
> 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-17-2008, 06:12 AM
zalek
 
Posts: n/a
Default Re: Newbie - problem accessing DB2 with Java program.

On Mar 16, 6:49 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
> zalek wrote:
> > 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


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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-17-2008, 06:12 AM
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
 
Posts: n/a
Default Re: Newbie - problem accessing DB2 with Java program.

zalek wrote:
> On Mar 16, 6:49 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>> zalek wrote:
>>> 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.

>
> 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-17-2008, 06:12 AM
zalek
 
Posts: n/a
Default Re: Newbie - problem accessing DB2 with Java program.

On Mar 16, 7:21 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
> zalek wrote:
> > On Mar 16, 6:49 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
> >> zalek wrote:
> >>> 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.

>
> > 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


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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-17-2008, 06:12 AM
Alex.From.Ohio.Java@gmail.com
 
Posts: n/a
Default Re: Newbie - problem accessing DB2 with Java program.

On Mar 16, 7:04 pm, zalek <zalekbl...@hotmail.com> wrote:
> On Mar 16, 7:21 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>
>
>
> > zalek wrote:
> > > On Mar 16, 6:49 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
> > >> zalek wrote:
> > >>> 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.

>
> > > 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

>
> 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/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-17-2008, 06:12 AM
Lew
 
Posts: n/a
Default Re: Newbie - problem accessing DB2 with Java program.

Alex.From.Ohio.Java@gmail.com wrote:
> 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.

--
Lew
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-17-2008, 06:12 AM
zalek
 
Posts: n/a
Default Re: Newbie - problem accessing DB2 with Java program.

On Mar 16, 9:37 pm, Alex.From.Ohio.J...@gmail.com wrote:
> On Mar 16, 7:04 pm, zalek <zalekbl...@hotmail.com> wrote:
>
>
>
> > On Mar 16, 7:21 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:

>
> > > zalek wrote:
> > > > On Mar 16, 6:49 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
> > > >> zalek wrote:
> > > >>> 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, butit
> > > >>> 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.

>
> > > > 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

>
> > 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/


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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-17-2008, 06:12 AM
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
 
Posts: n/a
Default Re: Newbie - problem accessing DB2 with Java program.

zalek wrote:
> On Mar 16, 7:21 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>> zalek wrote:
>>> On Mar 16, 6:49 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>>>> zalek wrote:
>>>>> 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.
>>> 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.

>
> 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 03-17-2008, 06:12 AM
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
 
Posts: n/a
Default Re: Newbie - problem accessing DB2 with Java program.

Alex.From.Ohio.Java@gmail.com wrote:
> 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:16 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com