Forums Register Login

jdbc program written in Eclipse3.2.1 to connect DB2

+Pie Number of slices to send: Send
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 query = "CREATE TABLE book ( NAME VARCHAR(20),ID INTEGER,RATE INTEGER)";
String query1 = "INSERT INTO book VALUES ( 'HFSJ',1,100)";
String query2= "INSERT INTO book VALUES ( 'JSPCOOKBOOK',2,90)";


try{
Class.forName("com.ibm.db2.jcc.DB2Driver");
}

catch( Exception ex) {
System.out.println(ex.getMessage());
}

try {

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

while(rs.next())
{
System.out.println(rs.getString("NAME")+" " +rs.getInt("ID")+" "+rs.getInt("MARKS"));
}


}

catch(SQLException e)
{
System.out.println(e.getMessage());
}

}
}


i got the error as "com.ibm.db2.jcc.DB2Driver 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.

riyazudeen.
+Pie Number of slices to send: Send
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).
+Pie Number of slices to send: Send
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.
These are the worst of times and these are the best of times. And this is the best tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1538 times.
Similar Threads
problem while accessing class file from a package
jdbc programm connecting DB2, error thrown in cmd as "null user id is not supported"
my java application doesn't update the table?
java DB2 program
Problem in output
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:21:27.