Connecting servlet program with db2 gives an error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Reshu Agarwal
    New Member
    • Jul 2010
    • 6

    Connecting servlet program with db2 gives an error

    java-class not found driver nt found...COM.ibm .db2.jdbc.app.d b2driver...

    program is:

    Code:
    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    
    public class EmployeeDetails extends HttpServlet
    {
    	static int i;
    	Connection con;
    	PrintWriter out;
    	ResultSet rs;
    	public void init()
    	{
    		i=0;
    		con=null;
    		out=null;
    		rs=null;
    	}
    	public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    
    	{
    		i++;
    		out=res.getWriter();
    		out.println("<B>You are the"+i+"visitor to visit this site.</B><BR><BR>");
    
    	try
    	{
    		Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
                    con=DriverManager.getConnection("jdbc:db2:DB");
    		PreparedStatement pstmt=null;
    		String query=null;
    		query= "Select emp_fname, address, age, desig from system.Employee_Master where id=?";
    		pstmt=con.prepareStatement(query);
    		pstmt.setInt(1,Integer.parseInt(req.getParameter("id")));
    		rs=pstmt.executeQuery();
    		out.println("<B><center>Employee Details </center></B><BR><BR>");
    		ResultSetMetaData rsmd= rs.getMetaData();
    		int colcount=rsmd.getColumnCount();		
                    out.println("<TABLE ALIGN = CENTER BORDER=1 CELLPADDING=2>");
    		out.println("<TR>");
    		for(int i=1; i<=colcount; i++)
    		{
    			out.println("<TH>" + rsmd.getColumnLabel(i)+"</TH>");
    		}
    		out.println("</TR>");
    		while(rs.next())
    		{
    			out.println("<TR>");
    			out.println("<TD>" + rs.getString("emp_fname") + "</TD>");
    			out.println("<TD>" + rs.getString("address") + "</TD>");		
    			out.println("<TD>" + rs.getString("age") + "</TD>");
    			out.println("<TD>" + rs.getString("desig") + "</TD>");
    			out.println("</TR>");
    		}
    		out.println("</TABLE>");
    		out.println("</BODY>");
    	}
    	catch(Exception e)
    	{
    		out.println(e.toString());
    	}
    	}
    	public void destroy()
    	{
    		try
    		{
    			i=0;
    			con.close();
    			out.close();
    			rs.close();
    		}
    	catch (SQLException se)
    	{
    		out.println(se.toString());
    	}
    	}
    }

    what i do????
    Last edited by Niheel; Jul 13 '10, 05:12 AM. Reason: please use code tags to display code
  • kleach
    New Member
    • Jun 2010
    • 15

    #2
    > java-class not found

    Java classes are found by setting the CLASSPATH variable correctly. On Unix these are in the instance user's home directory, under sqllib/java.

    Comment

    • Reshu Agarwal
      New Member
      • Jul 2010
      • 6

      #3
      connnecting servlet prgrm with db2

      yes sir...i have 2 zip files there...db2java .zip and sqll.zip....but i am working with netbeans...and when i put these files in src folder of project in netbeans it do not take it..as we cannot setpath with netbeans as i think...and by the runtime field of netbeans connection with db2 is done....but not through servlet...i am using window XP....

      Comment

      Working...