【问题标题】:java.sql.SQLException: No suitable driver found for jdbc:mariadb in a Gradle project (Intellij)java.sql.SQLException:在 Gradle 项目 (Intellij) 中找不到适合 jdbc:mariadb 的驱动程序
【发布时间】:2018-02-18 19:32:33
【问题描述】:

我在 IntelliJ 中有一个 Gradle 项目,我用它来控制我的依赖项,但我是 Gradle 新手,所以我可能做错了什么。

运行代码时出现此错误:

java.sql.SQLException: No suitable driver found for jdbc:mariadb://<db address>

build.gradle 文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'gs-rest-service'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

dependencies {
    // https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client
    compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '1.1.7'
}

我也在使用的 jdbc.properties 文件:

jdbc.drivers=com.mariadb.jdbc.Driver
jdbc.url=jdbc:mariadb://<db address>
jdbc.user=root
jdbc.password=password

我做错了什么?

【问题讨论】:

    标签: java gradle intellij-idea build.gradle


    【解决方案1】:

    您缺少对 MariaDB Java 驱动程序的依赖,因此出现此消息:

    java.sql.SQLException: No suitable driver found for jdbc:mariadb://<db address>
    

    您可以通过更新build.gradledependencies 块将MariaDB Java 驱动程序添加到您的类路径...

    dependencies {
        compile("org.springframework.boot:spring-boot-starter-web")
        compile("org.mariadb.jdbc:mariadb-java-client")
        testCompile('org.springframework.boot:spring-boot-starter-test')
    }
    

    【讨论】:

    • 抱歉,刚刚更新了答案以使其更清楚。
    猜你喜欢
    • 1970-01-01
    • 2017-06-14
    • 1970-01-01
    • 2013-07-04
    • 2016-11-28
    • 2011-08-02
    • 2012-08-28
    • 2015-07-05
    • 2010-11-25
    相关资源
    最近更新 更多