java.sql.SQLException: No suitable driver found for jdbc: mysql // localhost: 3306 / rch Spring MVC [duplicate]

0

Hello, I hope and someone can help me. I have a mysql connection problem with spring mvc and weblogic.

The exception thrown at me is the following.

  
    

Caused by: java.sql.SQLException: Not suitable driver found for jdbc: mysql // localhost: 3306 / rch at     java.sql.DriverManager.getConnection (DriverManager.java:689) at     java.sql.DriverManager.getConnection (DriverManager.java:208) at     org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager (DriverManagerDataSource.java:154)       at     org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver (DriverManagerDataSource.java:145)       at     org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver (AbstractDriverBasedDataSource.java:205)       at     org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection (AbstractDriverBasedDataSource.java:169)       at     org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection (DatasourceConnectionProviderImpl.java:122)       at     org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection (NonContextualJdbcConnectionAccess.java:35)       at     org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded (LogicalConnectionManagedImpl.java:106)       ... 56 more

  

This is my Datasource connection code.

   @Bean
    @Primary
    public DataSource rchDs() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql//localhost:3306/rch");
        dataSource.setUsername("root");
        dataSource.setPassword("admin");

        log.info(new StringBuilder("getDataSource:").append(" ").append(dataSource));
        return dataSource;
    }

and my deployment in weblogic and data source is working correctly.

I'm missing something to configure. I use spring mvc and mysql. Thanks.

    
asked by J V 05.08.2018 в 01:48
source

1 answer

0

Your application does not have the driver (the connector) for MySQL and therefore can not connect to the database.

  • If you use Maven in your project, add the corresponding dependency to your file pom.xml .

    <!-- dentro de la sección de dependencies -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.12</version>
    </dependency>
    
  • If you do not use Maven, download the MySQL connector and place the file .jar in the WEB-INF folder of the web project.

answered by 05.08.2018 в 03:56