![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Aug 2005
Posts: 26
Rep Power: 0
![]() |
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();
}
}
} |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 6
![]() |
Package names are case sensitive, IIRC, and "COM" is an unusual root. Try "com" instead.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Aug 2005
Posts: 26
Rep Power: 0
![]() |
still the same error unfortunately. I searched on the web for the URL so have no idea what it means.
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 6
![]() |
Is the DB2 driver jar in the classpath?
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Aug 2005
Posts: 26
Rep Power: 0
![]() |
probably not...
How do i do this? |
|
|
|
|
|
#6 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 6
![]() |
Quote:
java -classpath db2driver.jar;. YourClass |
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Aug 2005
Posts: 26
Rep Power: 0
![]() |
managed to get it working cheers.
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: Apr 2009
Posts: 1
Rep Power: 0
![]() |
Re: JDBC DB2 connection
Hi there,
I'm having the same problem. Could please tell me what you exactly did? Thx in advance David |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|