i am trying to retreive the contents of the table in my databse into a html form using servlets in tomcat.
here isthe code:

import java.io.*;
import java.lang.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ServletusingData extends HttpServlet{
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException{
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		String JDBC_DRIVER = "com.mysql.jdbc.Driver";
		String DATABASE_URL = "jdbc:mysql://localhost/mobilepaymentenabler";

		Connection connection;
		try{
			Class.forName( JDBC_DRIVER ).newInstance();
			connection = DriverManager.getConnection( DATABASE_URL, "root", "" );
			Statement statement = connection.createStatement(); 
			ResultSet columns = statement.executeQuery( "SELECT * FROM payer"); 
			while(columns.next()){ 
				int payerID = columns.getInt("payerID"); 
				String name = columns.getString("name"); 
				String address = columns.getString("adress");
				int phoneno=columns.getInt("phoneno");
				pw.println("<html> <head><title>Listing The Content of A Database</title></head><body> <p>Content of the payer table:</p> ");
				pw.println("<TR><TD>payerID</TD> <TD>name</TD> <TD>address</TD> <TD>phoneno</TD> </TR>");
				pw.println("<tr><td><%= payerID%></td> <td><%=name%></td> <td><%=address%></td> <td><%=phoneno%></td></tr> ");
				pw.println(" <%}%> </table> </body></html> ");
			}
		}catch (Exception e){
			pw.println(e);
		}finally{}
	}
}

and i am getting the following error:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

please help!!!

Do you have jar file with JDBC driver for MySQL?
NO? Download here

Is the driver in correct location ?
TOMCAT_DIRECTORY/webapps/YOUR_PROJECT/WEB-INF/lib
More on Tomcat Standard Directory Layout

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.