help: jdbc to db2 connectivity

speedyguy

Cyborg Agent
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

Excessive happiness
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.
 

amrutha

Right off the assembly line
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:
 
Top Bottom