Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 6th, 2006, 5:49 PM   #1
Konnor
Newbie
 
Join Date: Aug 2005
Posts: 26
Rep Power: 0 Konnor is on a distinguished road
JDBC DB2 connection

struggling to connect to a database i made in DB2.

The programs errors at the first line...

// load the DB2 Driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

with..



maybe some more configaration is required.

Any hints would be much obliged.

Just for reference, the rest of the program is:

class JDBCSample1 
{
	public static void main(String argv[]) 
	{
		try 
		{
		   // load the DB2 Driver
           Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
           // establish a connection to DB2
           Connection db2Conn = 
         DriverManager.getConnection
             ("jdbc:db2:test","","");
           // use a statement to gather data from the database
            Statement st = db2Conn.createStatement();
            String myQuery = "SELECT * FROM TEST"; 
           // execute the query
            ResultSet resultSet = st.executeQuery(myQuery); 
           // cycle through the resulSet and display what was grabbed
           // clean up resources
           resultSet.close();
           st.close();
           db2Conn.close();
       }
       catch (ClassNotFoundException cnfe)
       {
           cnfe.printStackTrace();
       }
       catch (SQLException sqle)
       {
           sqle.printStackTrace();
       }
	}
}
Konnor is offline   Reply With Quote
Old Mar 7th, 2006, 3:22 AM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 6 Arevos is on a distinguished road
Package names are case sensitive, IIRC, and "COM" is an unusual root. Try "com" instead.
Arevos is offline   Reply With Quote
Old Mar 7th, 2006, 4:55 AM   #3
Konnor
Newbie
 
Join Date: Aug 2005
Posts: 26
Rep Power: 0 Konnor is on a distinguished road
still the same error unfortunately. I searched on the web for the URL so have no idea what it means.
Konnor is offline   Reply With Quote
Old Mar 7th, 2006, 5:26 AM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 6 Arevos is on a distinguished road
Is the DB2 driver jar in the classpath?
Arevos is offline   Reply With Quote
Old Mar 7th, 2006, 7:10 AM   #5
Konnor
Newbie
 
Join Date: Aug 2005
Posts: 26
Rep Power: 0 Konnor is on a distinguished road
probably not...

How do i do this?
Konnor is offline   Reply With Quote
Old Mar 7th, 2006, 3:56 PM   #6
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 6 Arevos is on a distinguished road
Quote:
Originally Posted by Konnor
probably not...

How do i do this?
I've never used DB2 before, but you'll undoubtably need a JDBC driver for DB2 in order to connect to it. IBM will probably have this somewhere on its site. Once you have the driver, run your program like so:
java -classpath db2driver.jar;. YourClass
This tells Java to use the classes found in driver.jar, and in the current directory ('.' for short).
Arevos is offline   Reply With Quote
Old Mar 10th, 2006, 6:54 PM   #7
Konnor
Newbie
 
Join Date: Aug 2005
Posts: 26
Rep Power: 0 Konnor is on a distinguished road
managed to get it working cheers.
Konnor is offline   Reply With Quote
Old Apr 1st, 2009, 1:26 PM   #8
ddaudi8
Newbie
 
Join Date: Apr 2009
Posts: 1
Rep Power: 0 ddaudi8 is on a distinguished road
Re: JDBC DB2 connection

Hi there,

I'm having the same problem. Could please tell me what you exactly did?

Thx in advance

David
ddaudi8 is offline   Reply With Quote
Old Jul 8th, 2009, 4:13 AM   #9
amragman
Genemesis
 
amragman's Avatar
 
Join Date: Jul 2009
Posts: 44
Rep Power: 0 amragman is on a distinguished road
Re: JDBC DB2 connection

Just google for JDBC DB2 driver...download it...and include it in the classpath of your program!!
__________________
Genemesis
amragman is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC