• Post Reply Bookmark Topic Watch Topic
  • New Topic

MySQL Driver not found in Tomcat Question.  RSS feed

 
Brian K Swingle
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,
I'm having trouble with a servlet i wrote connecting to MySQL running on our VPS. The servlet uses
mysql-connector-java-3.1.0-alpha-bin.jar
MySQL driver located in the lib folder in tomcat on the VPS(Virtual Private Server). The problem is that the servlet located in the root directory can't find the Driver when i call the servlet form a simple html page the servlet generates my error html page diplaying start process java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver . I'll post the servlet code below. any help will be greatly appreciated.
Servlet Code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;

public class Test2 extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{ PrintWriter out = response.getWriter();
response.setContentType("text/html");
System.out.println("step1");
out.println("");
out.println("");
out.println("start process");
try
{
// The call to Class.forName explicitly loads the driver class
System.out.println("step8");
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
System.out.println("step2");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/123UpgradeFinder?user=root&password=plp08844");
System.out.println("step3");
if (conn != null) out.println("Connection Made");
System.out.println("step4");

conn.close();
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<H1>Hello World, this is an Servlet which connects mySQL!</H1>");

System.out.println("step5");
}
catch( Exception e ) {
System.out.println("step6");
out.println(e);
}
out.println("</body>");
out.println("</html>");
}
}
---------------------------------------------
Thanks,
Brian Swingle
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm wondering if the alpha of the connectorJ driver will still recognize this:
org.gjt.mm.mysql.Driver

Have you tried loading:
com.mysql.jdbc.Driver
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recommend setting up a MysqlDataSource object, and letting that manage the driver, etc. Example code:

I have found this to virtually eliminate the headaches involved with Class.forName(...).newInstance()
 
Brian K Swingle
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm giving that a try the only problem the compiler kicks back is on
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
It points to the "M" in MysqlDataSource saying "Cannot Resolve Symbol" and to every reference of MysqlDataSource after that. Is there something i missed? Do you want me to post the Sevlet code?
Thanks for all your help.
Brian Swingle
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!