Eroare Java Spring: Nu s-a putut obține conexiunea JDBC (Programare, Java, Mysql, Spring, Spring Jdbc)

user2758327 a intrebat.

Fac un mic exercițiu folosind cadrul Spring și JDBC și am primit următoarea eroare:

    Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:mysql:3306//localhost/springcore
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:812)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:868)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:876)
    at springcore.springcore.EmployeeJDBCTemplate.create(EmployeeJDBCTemplate.java:23)
    at springcore.springcore.EmployeeApp.main(EmployeeApp.java:23)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql:3306//localhost/springcore
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)

Pom.xml-ul meu:

<project  xmlns_xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi_schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>springcore</groupId>
  <artifactId>springcore</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>springcore</name>
  <url>http://maven.apache.org</url>

      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>

      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.1.0.RELEASE</version>
        </dependency>
        <!-- MySQL database driver -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.9</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>
      </dependencies>
    </project>

și Beans.xml:

<beans 
    xmlns_xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi_schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">

   <!-- Initialization for data source -->
   <bean id="dataSource" 
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
      <property name="url" value="jdbc:mysql:3306//localhost/springcore"/>
      <property name="username" value="root"/>
      <property name="password" value=""/>
   </bean>
<!-- Definition for employeeJDBCTemplate bean -->
   <bean id="employeeJDBCTemplate" 
      class="springcore.springcore.EmployeeJDBCTemplate">
      <property name="dataSource"  ref="dataSource" />    
   </bean>
</beans>

Database: MySQL, folosesc Xampp și phpmyadmin pentru a gestiona baza de date!IDE: esclipse, proiect Maven!

Îmi lipsesc bibliotecile sau ceva?

Vă rog să-mi spuneți unde greșesc :DT Mulțumesc anticipat!

Comentarii

  • pare a fi o problemă de driver destul de clară din stacktrace. vă rugăm să vă asigurați că url-ul de conectare este corect și că driverele sunt instalate în depozitul local m2 –  > Por vikeng21.
2 răspunsuri
GitzJoey

sunteți sigur că șirul de conexiune este corect?

url implicit

jdbc:mysql://localhost:3306/dbname

Bipil Raut

Curățați și construiți proiectul dvs..

Terminal server Tomcat și restart.

ia URL-ul corect.