gpt4 book ai didi

java.sql.SQLException : No suitable driver found for jdbc:mariadb in a Gradle project (Intellij)

转载 作者:行者123 更新时间:2023-11-30 02:14:59 25 4
gpt4 key购买 nike

我在 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

我做错了什么?

最佳答案

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

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

您可以通过更新 build.gradledependencies block 将 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')
}

关于java.sql.SQLException : No suitable driver found for jdbc:mariadb in a Gradle project (Intellij),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48855743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com