Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL using JDBC from Servlet

Status
Not open for further replies.

zorrinn

Programmer
Jun 12, 2002
7
CA
I am using MySQL for the first time. First I gave global permissions to all users. Then I wrote a simple JDBC application and it worked fine. Then I wrote a simple servlet to fetch and display data from the MySql DB. That is when I had the problem. My class path points to the .jar files having the mm.mysql.XXX driver files. Is there any variable I have to set in Tomcat inorder to make this work ?? I have copied the stack trace, and I will also copy the code. Please help.......!

******************** SOURCE CODE *************
import java.io.*;
....

public class MysqlExample extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException { try {
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost/test";
Connection con = DriverManager.getConnection(url, "dummy", "dummy");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from Author");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(&quot;<html>&quot;);
.....
...
while(rs.next()) {
int author_id = rs.getInt(1);
String first_name = rs.getString(2);
String last_name = rs.getString(3);
out.println(&quot;<tr><td>&quot; + author_id + &quot;</td><td>&quot; + first_name + &quot;</td><td>&quot; + last_name + &quot;</td></tr>&quot;);
}
out.println(&quot;</table><P><hr>&quot;);
out.println(&quot;</body>&quot;);
out.println(&quot;</html>&quot;);
}
catch( Exception e ) {
....
}}}
*************** STACK TRACE **************************

org.gjt.mm.mysql.Driver
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1394) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1243) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:130) at MysqlExample.doGet(MysqlExample.java:15) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
....
....
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174) at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012) at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107) at java.lang.Thread.run(Thread.java:536)

End of Stack Trace
 
Folks I have taken care of it myself. It's jus that from tomcat while running a servlet it doesn't seem to pick-up system CLASSPATH (that's where I put my MqSQl driver files.jar)

For Tomcat we need to put the driver files in $TOMCAT_HOME/lib or in my case it was /usr/tomcat/lib

Thanks again. The moderator can remove this thread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top