If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 and Java question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-16-04, 12:33
dmilks dmilks is offline
Registered User
 
Join Date: Aug 2002
Posts: 8
Question DB2 and Java question

Hi. I'm running a small custom Java utility on an AIX server connecting to a DB2 database. DB2 allows for implicit connections, which means that through the UNIX command line I can connect to the DB without providing a password. It knows that since I'm authenicated on the server, I must also be authenicated on the DB (assuming I have an account created at the DB level).

Is there a way to do this in Java? I want to connect to the same DB2 database in my Java utility without having to provide a password. Can this be done?

NOTE: I am calling the Java app/class from a KSH script.

Thanks!
- Dylan
Reply With Quote
  #2 (permalink)  
Old 12-16-04, 14:32
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I'm not sure if this is gonna work but you could try using the "app" (type 2) driver (COM.ibm.db2.jdbc.app.DB2Driver). You'll need to catalog your database locally and specify the jdbc url as "jdbc:db2:YOURDB".
Reply With Quote
  #3 (permalink)  
Old 12-17-04, 12:42
dmilks dmilks is offline
Registered User
 
Join Date: Aug 2002
Posts: 8
Hi. I'm getting an odd Java error. My class just tries to establish a connection to a DB2 database - that's it. Here's the error:

java.lang.NoClassDefFoundError: java/security/PrivilegedAction
at COM.ibm.db2.jdbc.app.DB2Driver.<init>(Compiled Code)
at
at TestConnect.main(Compiled Code)

The db2java.zip file is in the classpath. I've never seen this error before, and I'm unclear as to what the problem is.

Here's my code:

Connection db;
String dbURL = "jdbc:db2:icmdb01";
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
System.out.println("Connecting to Database URL = " + dbURL);
db = DriverManager.getConnection(dbURL);
System.out.println("Connected to " + dbURL + "\nNow closing DB...");
db.close();

Again, I'm running this on an AIX server. I've added all the necessary Java/DB2 packages to the classpath (I think).

Any ideas?
Reply With Quote
  #4 (permalink)  
Old 12-17-04, 14:24
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Looks like your JRE version doesn't match DB2 requirements. You'll probably need to install JRE that supports the version of DB2 you're using.
Reply With Quote
  #5 (permalink)  
Old 12-20-04, 13:18
dmilks dmilks is offline
Registered User
 
Join Date: Aug 2002
Posts: 8
Thanks. The problem was that I also needed to have the rt.jar file in my classpath. Once I added this it worked.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On