运行报错:com.alibaba.druid.pool.DruidDataSource : create connection error

来源:2-3 Mybatis接入SpringBoot项目

小熊熊写代码

2020-02-12 01:09

2020-02-12 01:06:41.591 ERROR 66279 --- [reate-571481216] com.alibaba.druid.pool.DruidDataSource   : create connection error, url: jdbc:mysql//localhost:3306/dbSeckill?serverTimezone=UTC, errorCode 0, state null


java.sql.SQLException: connect error, url jdbc:mysql//localhost:3306/dbSeckill?serverTimezone=UTC, driverClass com.mysql.jdbc.Driver

at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1533) ~[druid-1.0.31.jar:1.0.31]

at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2109) ~[druid-1.0.31.jar:1.0.31]

老师你好,这是什么原因呢。


写回答 关注

4回答

  • 小熊熊写代码
    2020-02-13 23:10:19

    应该写成 jdbc:mysql://localhost:3306/dbSeckill,我在mysql后面少写了一个冒号。。。

  • 小熊熊写代码
    2020-02-13 22:19:01
    server:
      port: 8888
    mybatis:
      mapper-locations: classpath:mapping/*.xml
    
    spring:
      datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        name: dbSeckill
        url: jdbc:mysql//localhost:3306/dbSeckill?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT
        username: 
        password: 
    
        type: com.alibaba.druid.pool.DruidDataSource


  • 小熊熊写代码
    2020-02-13 22:07:24
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.2.4.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.xlx</groupId>
        <artifactId>seckill</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>seckill</name>
        <description>Online Seckill Project</description>
        <properties>
            <java.version>1.8</java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>8.0.19</version>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jdbc</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <!--druid 的数据源-->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.0.5</version>
            </dependency>
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>1.3.1</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <dependencies>
                        <dependency>
                            <groupId>org.mybatis.generator</groupId>
                            <artifactId>mybatis-generator-core</artifactId>
                            <version>1.3.5</version>
                        </dependency>
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>5.1.41</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <id>mybatis generator</id>
                            <phase>package</phase>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <!-- 允许移动生成的文件 -->
                        <verbose>true</verbose>
                        <!-- 允许自动覆盖文件 -->
                        <overwrite>true</overwrite>
                        <configurationFile>
                            src/main/resources/mybatis-generator.xml
                        </configurationFile>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    </project>


  • 小涛lqq
    2020-02-13 17:24:23

    贴上配置文件看看,properties或者yml

SpringBoot构建电商基础秒杀项目

应用SpringBoot快速搭建拥有用户、商品、交易及秒杀活动的电商秒杀应用。

49065 学习 · 954 问题

查看课程

相似问题