Apostille Caelum fj21 mysql driver error

Asked

Viewed 486 times

1

Good afternoon, everyone,

Starting I am studying the Java WEB workbook from Caelum but the following error is appearing. I already imported the Mysql driver, I switched between the commented line and commented the top line, but it is not working the browser error is

HTTP Status 500 - java.sql.Sqlexception: No suitable driver found for jdbc:mysql://localhost/fj21

package br.com.caelum.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;

//class conexão com o banco de dados
public class ConnectionFactory {

    public Connection getConnection(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            //DriverManager.registerDriver(new com.mysql.jdbc.Driver());
            return DriverManager.getConnection("jdbc:mysql://localhost/fj21", "root", "822674");
        } catch (Exception e) {
            throw new RuntimeException(e);

        }
    }
}

Stack trace:

GRAVE: Servlet.service() for servlet [br.com.caelum.servlet.AdicionaContatoServlet] in context with path [/fj21-agenda] threw exception
java.lang.RuntimeException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/fj21
    at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:15)
    at br.com.caelum.dao.ContatoDao.<init>(ContatoDao.java:23)
    at br.com.caelum.servlet.AdicionaContatoServlet.service(AdicionaContatoServlet.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/fj21
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:13)
    ... 24 more
  • 2

    How you installed Mysql ?

  • 1

    You added Mysql Nector to the project?

  • yes added, and also tried to put right into the project folder

  • installed Mysql executable for windows, the first example of the non-web workbook went all right and using the connection test class in the web project also works

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.