Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java createDatabaseIfNotExist=true不在maven项目的.properties文件中工作_Java_Database_Hibernate_Maven_Jdbc - Fatal编程技术网

Java createDatabaseIfNotExist=true不在maven项目的.properties文件中工作

Java createDatabaseIfNotExist=true不在maven项目的.properties文件中工作,java,database,hibernate,maven,jdbc,Java,Database,Hibernate,Maven,Jdbc,我有一个maven项目,它连接到一个已经存在的数据库。但是我想更改它,以便在数据库不存在的情况下。它被创建。因此,我在这行中添加了额外的代码?createDatabaseIfNotExist=true dataSource.url=jdbc:mysql://localhost/rays-database?createDatabaseIfNotExist=true 我犯了很多错误,所以我的问题是;是否有任何额外的配置需要使用?createDatabaseIfNotExist=true 我还尝试添加

我有一个maven项目,它连接到一个已经存在的数据库。但是我想更改它,以便在数据库不存在的情况下。它被创建。因此,我在这行中添加了额外的代码
?createDatabaseIfNotExist=true

dataSource.url=jdbc:mysql://localhost/rays-database?createDatabaseIfNotExist=true

我犯了很多错误,所以我的问题是;是否有任何额外的配置需要使用?createDatabaseIfNotExist=true

我还尝试添加端口号,但没有产生任何差异,这是我没有预料到的

dataSource.url=jdbc:mysql://localhost:3306/rays-database?createDatabaseIfNotExist=true
这是我的.properties文件:

 dataSource.driverClassName=com.mysql.jdbc.Driver
 dataSource.url=jdbc:mysql://localhost/rays-database?createDatabaseIfNotExist=true
 dataSource.username=root
 dataSource.password=

 hibernate.dialect=org.hibernate.dialect.MySQLDialect
 hibernate.show_sql=true
 hibernate.hbm2ddl.auto=create

请检查这个。希望对您有所帮助。您会遇到什么样的错误?

您可以尝试此错误,您必须在数据库名称上添加端口并删除此(-)

spring.datasource.url = jdbc:mysql://127.0.0.1:3306/DbName?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&useUnicode=yes&characterEncoding=UTF-8&allowPublicKeyRetrieval=true

很简单,但是您使用的是哪个版本的mysql JDBC驱动程序?您好,谢谢您的回复@Tunaki我正在使用5.1.6。我已经用.properties文件更新了我的问题。看起来差不多。我遇到了一些错误,比如,与内存泄漏有关,以及我的sql语法有问题,创建名为“configureDataSource”的bean时出错将hibernate.dialent=org.hibernate.dialent.mysqldialent替换为hibernate.dialent=org.hibernate.dialent.mysql5dialen我将5添加到该方言中,但仍然没有更改警告:web应用程序[/RaysRentalSystem]似乎已启动名为[MySQL语句取消计时器]的线程但却未能阻止它。这很可能会造成内存泄漏。线程的堆栈跟踪: