0
votes

I've got a strange problem.

  • I created a web application on Eclipse Luna;
  • Servlet container Tomcat 7 or tomcat 8 (the problem is the same);
  • jdbc connector (last version);

With a NON web application, I do a normally connection to my database. When i try the same connection on the Servlet in a web app, it doesn't work, the error is:

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/webtech

I put the jar library in the lib folder into web-inf folder, I put the jar into the apache-tomcat lib folder, I put the jar into the build path folder, I try to do the "class for name" method, but nothing works for me.

The servet is a simple "hello world" servlet just to test the connection.

1
can you find the JDBC-jar in your resulting war/ear file?desperateCoder
I dont have war filesMax
Are you building the project with maven or just the IDE?sirandy

1 Answers

1
votes

I solved with the following:

  • Eclipse Luna
  • Tomcat 7
  • Jdk 131
  • jbdc connector

I put the jar file of the connector into the lib folder (the one inside the web-inf folder)

with the code:

String connectionString="jdbc:mysql://localhost:3306/webtech";
Connection con=null;
try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
try {
        con=DriverManager.getConnection(connectionString,"root","root");
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }