Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here i am trying to insert two values to database table . Database i am using is DB2 and IDE is eclipse . I am getting ,

java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver exception .

my code in dopost is ,

Java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		response.setContentType("text/html");
		PrintWriter out=response.getWriter();
		
		String uname=request.getParameter("uname");
		String pass=request.getParameter("pass");
		/*if(uname.equals("admin")&&pass.equals("admin"))
		{out.println("Sussces");}else{out.println("NO");}*/
		try {
			Class.forName("com.ibm.db2.jcc.DB2Driver");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Connection con;
		try {
			con = DriverManager.getConnection("jdbc:db2:MYDB","","");
			Statement st=con.createStatement();
			int count=st.executeUpdate("insert into Login values('" + uname +"','"+pass+"')");
			out.println("Insertion success:"+count);
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}



and i have included required Jar files also.
Posted
Comments
ridoy 26-Oct-13 2:41am    
clearly there is a problem in Class.forName("com.ibm.db2.jcc.DB2Driver"), check this line first.
Richard MacCutchan 26-Oct-13 5:41am    
Are you sure the correct jar file can be found within the directories listed in your classpath?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900