Can't find the jdbc driver class for mySQL
Hi, can somebody help?
The following servlet gives me the error message when run on IE.
Error message is "java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver".
The same jdbc connection on an application has no problem, only when it runs on a browser. Even if I use jdbc-odbc driver, that would produce the same kinda error. What's wrong? Thanks so much!
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class showDB extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("Text/html");
ServletOutputStream out = res.getOutputStream();
out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body>");
try
{
String url = "jdbc:odbc:twdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(url);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from company");
while(rs.next())
{
out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3) + "<br>");
}
rs.close();
st.close();
con.close();
}
catch(SQLException s)
{
out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
}
catch(Exception e)
{
out.println(e.toString());
}
finally
{
out.println("</body>");
out.println("</html>");
}
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
doPost(req, res);
}
}
This is my machine:
1. Java sdk 1.4
2. Tomcat servlet container
3. mySQL