Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

prolem with DB2Driver and jar file

13 views
Skip to first unread message

Limei Zhang

unread,
Jul 2, 2002, 2:34:48 PM7/2/02
to
Hi, there,

I am writting a simple test file as follow:

import java.sql.*;
import COM.ibm.db2.app.*;
import COM.ibm.db2.jdbc.net.*;

public class Test3 {

public static void main(String[] args) {
try{


Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();

Connection con = DriverManager.getConnection( dbname,
username, password);
System.out.println("The connection is " + con);
}catch(SQLException ex){

}catch (Exception E) {
}
}
}

it runs as expected when I am using

java Test3

However, when compact it in a jar file, and run it under same directory, I
got an error message:

Unable to load driver.
java.lang.ClassNotFoundException: COM.ibm.db2.jdbc.net.DB2Driver
at java.lang.Throwable.<init>(Throwable.java:96)
at java.lang.Exception.<init>(Exception.java:44)
at
java.lang.ClassNotFoundException.<init>(ClassNotFoundException.java:71)
at java.net.URLClassLoader.findClass(URLClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:293)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:275)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java:134)
at Test3.main(Test3.java:21)

Could anyone give me a hint to solve this problem? Thanks in advance.

zlm


Dirk Wollscheid

unread,
Jul 2, 2002, 4:05:09 PM7/2/02
to
Limei Zhang wrote:
> Hi, there,
>
> I am writting a simple test file as follow:
>
> import java.sql.*;
> import COM.ibm.db2.app.*;
> import COM.ibm.db2.jdbc.net.*;
>
> public class Test3 {
>
> public static void main(String[] args) {
> try{
>
>
> Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();
>
> Connection con = DriverManager.getConnection( dbname,
> username, password);
> System.out.println("The connection is " + con);
> }catch(SQLException ex){
>
> }catch (Exception E) {
> }
> }
> }
>
> it runs as expected when I am using
>
> java Test3
>
> However, when compact it in a jar file, and run it under same directory, I
> got an error message:

Could it be that you modfied the CLASSPATH to include that new jar and
accidently removed db2java.zip from it?

You could do a "javap COM.ibm.db2.jdbc.net.DB2Driver" to see if this
class can be loaded with the *current* CLASSPATH settings. If it can't
be loaded then try and add ...sqllib\java\db2java.zip

Dirk

PS: You'd be better off using Eclipse http://www.eclipse.org . That's an
open source Java IDE (donated by IBM) that takes a lot of the manual
error prone CLASSPATH settings environment out of the picture.


Limei Zhang

unread,
Jul 2, 2002, 4:28:00 PM7/2/02
to
Hi, Dik,

Thanks for response.

Yes, I tried that before with command Z:\temp\DBS>javap
COM.ibm.db2.jdbc.app.DB2Driver
and I found that class.

when I run this jar file, I used command
Z:\temp\DBS>java -jar myjarfile

I wonder if I need specify the classpath somehow.

Thanks again for help

zlm

Dirk Wollscheid

unread,
Jul 2, 2002, 5:29:43 PM7/2/02
to
Limei Zhang wrote:
> Hi, Dik,
>
> Thanks for response.
>
> Yes, I tried that before with command Z:\temp\DBS>javap
> COM.ibm.db2.jdbc.app.DB2Driver
> and I found that class.
>
> when I run this jar file, I used command
> Z:\temp\DBS>java -jar myjarfile
>
> I wonder if I need specify the classpath somehow.


Do a (in a DB2 command window, if you're using a regular command prompt
you have to locate the sqllib directory. Also if you have spaces in the
path you may have to put double quotes around the ;...zip part)

SET CLASSPATH=%CLASSPATH%;%DB2PATH%\sqllib\java\db2java.zip

Now

javap COM.ibm.db2.jdbc.app.DB2Driver

and your app should work.

Dirk

Limei Zhang

unread,
Jul 2, 2002, 7:01:20 PM7/2/02
to
Hi, Dirk,

Thanks again for your suggestion.
I have just tried your suggestion.
in a regular command window, I set the classpath as you specified (I have
locate the sqllib directory)
javap COM.ibm.db2.jdbc.app.DB2Driver and javap
COM.ibm.db2.jdbc.app.DB2Driver
both these two classes has been found with message like this:
****************
Compiled from DB2Driver.java
public class COM.ibm.db2.jdbc.app.DB2Driver extends java.lang.Object
implements java.sql.Driver {
public static final int MajorVersion;
public static final int MinorVersion;
public static boolean loaded;
protected int traceOn;
public static final java.lang.String buildLevel;
static {};
public COM.ibm.db2.jdbc.app.DB2Driver() throws java.sql.SQLException;
protected native int SQLAllocEnv();
protected native int SQLFreeEnv();
protected native java.lang.String SQLGetTracePath(java.lang.Integer,
java.lang.Integer, java.lan
g.Integer);
public boolean acceptsURL(java.lang.String) throws
java.sql.SQLException;
public java.sql.Connection connect() throws java.sql.SQLException;
public synchronized java.sql.Connection connect(java.lang.String,
java.util.Properties) throws j
ava.sql.SQLException;
public void finalize() throws java.sql.SQLException;
public native java.lang.String getDLLVersion();
public int getMajorVersion();
public int getMinorVersion();
public java.sql.DriverPropertyInfo getPropertyInfo(java.lang.String,
java.util.Properties)[];
public int getRelease();
public boolean jdbcCompliant();
public static void setLanguage(java.lang.String);
public java.lang.String toString();
}
***************
however, when I tried to run jar file under same directory

java -jar Myjarfile

it still give me the same error message.

Could you give me other suggestion? thanks very much for your help.

zlm


Dirk Wollscheid

unread,
Jul 3, 2002, 11:33:24 AM7/3/02
to
Limei Zhang wrote:
>
> java -jar Myjarfile


I don't know about how that -jar option exactly influences the
CLASSPATH. SO I suggest that you add Myjarfile to the CLASSPATH
and call the app with

java MyMainClass

This way it uses the settings from the CLASSPATH env variable and we've
verified that this is correct.

If you need more help, I would suggest you ask on a Java newsgroup since
this is clearly not a DB2 problem.

Reagrds, Dirk

Limei Zhang

unread,
Jul 3, 2002, 12:20:53 PM7/3/02
to
Hi, Dirk,

I solved the problem by following your suggestion. thanks

zlm

"Dirk Wollscheid" <wol...@us.ibm.com> wrote in message
news:3D231944...@us.ibm.com...

0 new messages