File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes IDEs, Version Control and other tools and the fly likes jdbc program written in Eclipse3.2.1 to connect DB2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "jdbc program written in Eclipse3.2.1 to connect DB2 " Watch "jdbc program written in Eclipse3.2.1 to connect DB2 " New topic

jdbc program written in Eclipse3.2.1 to connect DB2

riyaz udeen
Ranch Hand

Joined: Sep 11, 2005
Posts: 66
hye every one. i wrote a jdbc program in Eclipse 3.2.1 java perspective in order to connect Db2. the code is as follows:

import java.sql.*;

public class jdbc {

public static void main( String arg[]) {

Connection c = null;
Statement st = null;
ResultSet rs;
String query1 = "INSERT INTO book VALUES ( 'HFSJ',1,100)";
String query2= "INSERT INTO book VALUES ( 'JSPCOOKBOOK',2,90)";


catch( Exception ex) {

try {

c = DriverManager.getConnection("jdbc b2://localhost:50000/sample?UserID=pentium4&password=18may2003");
st = c.createStatement();
st.executeUpdate("INSERT INTO BOOK VALUES ( 'SCJP',1,200)");
rs= st.executeQuery("SELECT * FROM BOOK");

System.out.println(rs.getString("NAME")+" " +rs.getInt("ID")+" "+rs.getInt("MARKS"));


catch(SQLException e)


i got the error as " No suitable driver"
but i have placed the jar files (C:\Program Files\IBM\SQLLIB\java\db2jcc_license_cu.jar;C:\Program Files\IBM\SQLLIB\java\db2jcc.jar) in classpath environmental system variables.

can you kinldy provide me sollution. thanks in advance.

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
When you run a program from Eclipse, the classpath environment variable isn't used. Instead you need to add the jar file to the projects build path, or to the classpath of the launch configuration (in the Run... dialog).

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

JDBC drivers don't need to be in the build path. Only in the runtime path. Depends on if its a plugin project or a java project how you can accomplish that.
It is sorta covered in the JavaRanch Style Guide.
subject: jdbc program written in Eclipse3.2.1 to connect DB2
jQuery in Action, 3rd edition