5 messages in com.mysql.lists.javaProblem with mm driver and servlets| From | Sent On | Attachments |
|---|---|---|
| Edilmar Alves | 09 Nov 2000 10:03 | |
| Edilmar Alves | 09 Nov 2000 10:56 | |
| Igor Fedulov | 09 Nov 2000 11:21 | |
| melroy c d'souza | 09 Nov 2000 18:00 | |
| melroy c d'souza | 10 Nov 2000 07:40 |
| Subject: | Problem with mm driver and servlets![]() |
|---|---|
| From: | melroy c d'souza (dso...@CS.SC.EDU) |
| Date: | 11/09/2000 06:00:13 PM |
| List: | com.mysql.lists.java |
Hi,
I have a perfectly running program using MySQL and mm driver. I also have servlets running.(I'm using Apache tomcat) The problem however is that when I try to run the database connectivity program in servlets (simple retreival of some fields), I have errors. I have got the error down to ClassNotFoundException.
I am really confused and frustrated because I tried all possible things out and went through the list serv archive. Colud anybody suggest anything that I could try out.
Thanks in advance. My code is below if needed.
import java.io.* ; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*;
public class db extends HttpServlet { Connection con ; String MYSQL_HOST = "localhost"; String MYSQL_DB = "dbname"; String MYSQL_USER = "user"; String MYSQL_PASSWD = "pwd"; String MYSQL_TABLE = "stud"; String url="jdbc:mysql://" + MYSQL_HOST + "/" + MYSQL_DB +"?user=" + MYSQL_USER + "&password=" + MYSQL_PASSWD;
String queryGetStudents = "Select ssn, name from Student"; Statement stmt1; String error = "No error";
public void init(ServletConfig conf) throws ServletException { try { Class.forName("org.gjt.mm.mysql.Driver").newInstance(); con = DriverManager.getConnection(url); stmt1 = con.createStatement();
} catch(Exception e) { error = "ClassNotFoundException: "; error = error + e.getMessage(); System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); e.printStackTrace(); }
} public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String reqParam = req.getParameter("ID"); ResultSet rs = null; String temp = null; try { if (stmt1 != null) rs = stmt1.executeQuery(queryGetStudents); else temp = "Did not work"; out.println("<html>"); out.println("<body>"); out.println("<head>"); out.println("<title>Database Query</title>"); out.println("</head>"); out.println("<body>"); out.println("<b>" + reqParam + "<//b>"); if (rs != null) { while (rs.next()) {
out.print(" "); out.println(rs.getString("name")); out.print(" "); out.println(rs.getInt("ssn")); }
} else out.println(temp); if (con == null) out.println("<br>No connection"); out.println("<br>" + error); out.println("</body>"); out.println("</html>"); if (stmt1 != null) stmt1.close(); } catch(SQLException ex) { out.println("SQLException: " + ex.getMessage()); }
} // doGet
}// db




