0

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)
Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78
beseul
  • 1
  • 1

2 Answers2

1

Try removing space between = and username and password.

spring.datasource.username=root
spring.datasource.password=root
Alien
  • 15,141
  • 6
  • 37
  • 57
  • 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] https://stackoverflow.com/questions/43181853/spring-jdbc-using-application-properties-file?rq=1 – beseul Jul 01 '18 at 05:30
0

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.

beseul
  • 1
  • 1