springboot/jpa can't connect to mysql with username “@localhost” using password no?

Multi tool use
springboot/jpa can't connect to mysql with username “@localhost” using password no?
I'm trying to connect to MySQL database.
persistent.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="myApp">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<!-- TODO: Change file location to your H2 database ! -->
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://localhost:3306/myDB"/>
<property name="hibernate.dialect"value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
application.properties
spring.datasource.url = jdbc:mysql://localhost:3306/myDB?useSSL=false
# Username and password
spring.datasource.username = root
spring.datasource.password = root
Error
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
2 Answers
2
Try removing space between =
and username
and password
.
=
username
password
spring.datasource.username=root
spring.datasource.password=root
thanks for the answer but doesn't change. I still have the error.Just added mysql-connector-java version. I think about deleting this application.properties file. After some researches, may be i should try this way [named hyperlinks] stackoverflow.com/questions/43181853/…
– beseul
Jul 1 at 5:30
Looks like problem came from drivers version
Now i use :
Mysql Connector : 5.1.36
Hibernate-Entitymanager 5.2.10
Hibernante-core 4.3.10
Application.properties deleted
No more use of any spring-boot dependencies.
persistence.xml :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="myapp" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.myapp.jpa.commande</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myDB" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
</properties>
</persistence-unit>
It's all ok now.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
@Mikhail Kholodkov, thank you for formatting. I'll do my best to use good practices.
– beseul
Jun 30 at 23:56