英文:
Spring / Gradle project using Hibernate issuing a warning (error to my partner) about not being able to connect to database
问题
我正在使用IntelliJ进行Spring/Gradle项目开发,想要使用Hibernate与数据库建立连接。我已经在gradle构建文件中添加了以下依赖:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java'
我还创建了一个HibernateConfig类,从我的应用程序属性文件中获取dbUrl,dbUsername,dbPassword
。当我运行项目时,我收到以下警告:
2020-09-11 18:37:23.593 WARN 14996 --- [ restartedMain] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: 无法获取连接以查询metadata:找不到适用的驱动程序jdbc:mariadb://localhost:3306/data_beer_tag
当我的合作伙伴从GitLab拉取代码时,他收到了错误,而不是警告?您有什么想法,我可能做错了什么?据我所知,我不应该单独下载驱动程序,gradle会处理所有依赖关系。
英文:
I am working on a Spring/Gradle project using IntelliJ and I want to use Hibernate to connect with the database. I implemented :
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java'
in my gradle build file.
I have also created a HibernateConfig class which takes dbUrl, dbUsername, dbPassword
from my application properties file. When I run the project I get the following warning:
2020-09-11 18:37:23.593 WARN 14996 --- [ restartedMain] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : No suitable driver found for jdbc:mariadb://localhost:3306/data_beer_tag
When my partner pulled it from GitLab, he received not a warning but an error? Any Idea what I could be doing wrong? As far as I know I am not supposed to download the drivers separately and gradle is taking care of all dependancies.
答案1
得分: 1
你的连接字符串显示你正在使用MariaDB,使用MariaDB驱动程序而不是MySQL驱动程序依赖可能会解决你的问题。
implementation 'org.mariadb.jdbc:mariadb-java-client:2.6.2'
英文:
Your connection string shows that you are using MariaDB, Adding MariaDB driver instead of MySQL driver dependency may solve your problem.
implementation 'org.mariadb.jdbc:mariadb-java-client:2.6.2'
答案2
得分: 0
我通过将URL中的mariadb部分更改为mysql来解决了这个问题。虽然不是服务器生成的方式,但它能够正常工作。
英文:
I solved the issue by changing the mariadb part of the url with mysql. It is not as the server generated it but it works.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论