DIGIT-ARC read-only archive · snapshot: July 23, 2026

help: jdbc to db2 connectivity

5 posts · originally from https://geek.digit.in/community/threads/help-jdbc-to-db2-connectivity.138687/

speedyguy
speedyguy Original post #1
Mar 31, 2011 at 11:29 AM
im using eclipse 3.3 to create a dynamic web project (jsp) using websphere (apache geronimo) server and db2....

i have used the following code to connect to db2 from jsp-

Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:db2://localhost:50000/VIR_CLS","Abhinav","studioworks");
String sql="SELECT id from login";
Statement st=con.createStatement();
ResultSet rs= st.executeQuery(sql);
........

i have got the database up and connected in my "datasource explorer" in eclipse but how do retrieve data to my jsp pages.

on exporting it to server and running i get this error message on 1st line of connection code -



java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
java.lang.Class.forNameImpl(Native Method)
java.lang.Class.forName(Class.java:130)
org.apache.jsp.login_jsp._jspService(login_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:806)


any help possible?
thanks

Enjoy~!
furious_gamer
Mar 31, 2011 at 11:42 AM
Try to put the DB2 jar file under WEB-INF/lib folder

And to get result in JSP

1. Iterate the resultset and store the values in hashmap
2. Pass the hash map to jsp page in request scope (Imp : Don't use session scope unless you need these values for a long time)
3. Retrieve the hashmap in JSP page, use iterator to display the results.
speedyguy
Mar 31, 2011 at 11:57 AM
u mean db2jcc.jar?

hey thanks big time...i got it finally...thanks a lot

Enjoy~!
furious_gamer
Mar 31, 2011 at 11:59 AM
^^ Yes. How you passed the value? Using request or session?
A
amrutha #5
Oct 13, 2011 at 9:39 PM
thank u mam.i paste the db2jcc.jar file in web-inf/lib .my servlet run and i got result.
thanku very much mam::oops: