0

I try to include a MySQL-DB in my project.

I've installed MySQL program, created a DB (schema) and set password and username for the access-authentification.

Included pom-file dependencies and so on.

Now I'm stuck with my application.properties:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/asndb
spring.datasource.username=root
spring.datasource.password=asnTeam1
spring.jpa.hibernate.ddl-auto=create

In the MySQL Manager I can see all properties from my models, so the connection should work, right?

What do I wrong? Do I need the MySQL client?

UPDATE changed application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/asndb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=asnTeam1
spring.jpa.hibernate.ddl-auto=create
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1

spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.jpa.show-sql = true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

spring.datasource.platform=mysql
spring.datasource.schema=schema-mysql.sql
spring.datasource.data=data-mysql.sql
spring.datasource.initialize=true
spring.datasource.continue-on-error=true

Now I want to open with MySQL client my data.sql file. But there are erros in my sql syntax. Following an insert statement:

INSERT INTO USER (FIRST_NAME, LAST_NAME, USERNAME, PASSWORD, USER_ROLE) VALUES('Admin', 'Istrator', 'admin', '$2a$10$W9xQIwa/FstPUvcbzJXnQ.XjVdTyIcCEp.g6VCq1gYuSsQNjJjbJG', 'ADMIN')

INSERT INTO USER (FIRST_NAME, LAST_NAME, USERNAME, PASSWORD, USER_ROLE) VALUES('Bernd', 'Menia', 'bernd', '$2a$10$6dQcayeT/JAFvgFvzIjlcew5z9cmdCrGlv57.BGnIKvPXTDsQm7hG', 'PARENT')
INSERT INTO PARENT (FAMILY_STATUS, LOCATION, POSTCODE, STREET_NAME, IMG_NAME, STATUS, ID) VALUES ('MARRIED', 'Innsbruck', '6020', 'Bahnhofstraße', 'john.jpg',TRUE, SELECT ID FROM USER WHERE USERNAME = 'bernd')

What do I wrong?

SOLUTION:

insert the larger application.properties from above and for a persistent DB comment out the ddl-auto=true and initialize=true after the first spring-boot.

User is a reserved keyword in MySQL, so it is not allowed to use.

to fill a mySQL DB with data.sql file from spring-app is not possible, so I open the file via MySQL-Workbench and execute the statements.

7
  • what is the error ? Please add the stack trace Commented Apr 19, 2017 at 14:17
  • updated my question with the error message Commented Apr 19, 2017 at 14:28
  • @akuma8 added some information to my question above Commented Apr 19, 2017 at 15:04
  • it seems like the issue comes from timezone configuration. This can help you : stackoverflow.com/questions/7605953/… or this : stackoverflow.com/questions/7605953/… Commented Apr 19, 2017 at 15:20
  • thx.. made an update to my question .. Commented Apr 19, 2017 at 15:53

2 Answers 2

3

Came across to a similar problem from this post. Hope this helps.

Instead of

spring.datasource.url=jdbc:mysql://localhost:3306/asndb

Try this:

spring.datasource.url=jdbc:mysql://localhost:3306/asndb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
Sign up to request clarification or add additional context in comments.

4 Comments

thanks that helps.. but now there are no data from my data.sql in the DB anymore
try to add some data into your DB using mySQL commands from your console and check it.
it doesn't work. when i re-execute the SFW-statement the table is empty. I tried to open my data.sql file but it says there are errors in my sql syntax ... details above in the question
user is a reserved keyword in SQL. So, you can't use that as a table name. Create a table with another name like user_table. Check this Link - drupal.org/docs/develop/coding-standards/… @SteveOhio
1

To insert data in your database tables, be sure that the database is opened, so in your MySQL client, begin by :

mysql>use asndb;

And check that your tables : user and parent realy exist :

mysql>show tables;

After that you can insert your data :

INSERT INTO asndb.USER(.....);

And USER you can't use it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.