Solution that gives an error when trying to connect to DB (MySQL) in Java

Post test and memo memo so as not to forget ...

usage environment

eclipse 2018 MySQL 5.6

phenomenon

When I try to display the value in SQL with java, It throws the following error.

Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '“Œ‹ž (•W€Žž)' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

About a year after touching the program ... I still can't read the error, but ... I wondered what Timezone was, so I decided to look it up ...

Discovered while investigating! !! [Link] https://qiita.com/KKZ@github/items/e3f594b04c9233a86419 I arrived at this person's article.

At the bottom of the article

jdbc:mysql://localhost:xxxx/xxxx ?useUnicode=true& useJDBCCompliantTimezoneShift=true& useLegacyDatetimeCode=false& serverTimezone=UTC I wrote in the URL, and the error disappeared.

Explanation below (I'm sorry if I make a mistake)

useUnicode=true Do you use Unicode? YES !! (I feel absolutely different ...)

useJDBCCompliantTimezoneShift=true When converting timezone information for TIME / TIMESTAMP / DATETIME values, Does the driver use JDBC-aware rules? YES

useLegacyDatetimeCode=false

In MySQL Connector / J 5.1.6, the processing around the time has been rewritten, and by setting useLegacyDatetimeCode = false, time zone conversion etc. are automatically handled.

That's right Do you do time zone conversion or yourself? NO! !! → Will do it automatically

By the way, In MySQL Connector / J 6, including the useLegacyDatetimeCode property All properties around the old timezone are deleted.

Was written in the link below. Lol [Link] https://vividcode.hatenablog.com/entry/mysql/connector-j-5.1-use-legacy-datetime-code

serverTimezone=UTC The server time zone is UTC!

It feels like I said ...

** @ KKZ-san ... Thank you! !! ** **

Ah, I'm going to get angry if someone in the company sees me ... crying ...

Recommended Posts

Solution that gives an error when trying to connect to DB (MySQL) in Java
Summary when trying to use Solr in Java and getting an error (Solr 6.x)
407 error when trying to access an HTTPS site in Java via an authenticated proxy
Resolved the error that occurred when trying to use Spark in an environment where Java 8 and Java 11 coexist.
[Java] Connect to MySQL
Connect to DB with Java
Connect to MySQL 8 with Java
About the solution of the error that occurred when trying to create a Japanese file of devise in the Docker development environment
How to solve the unknown error when using slf4j in Java
[WSL] Solution for the phenomenon that 404 is displayed when trying to insert Java with apt (personal memo)
Error when trying to use heroku command
What to do and how to install when an error occurs in DXRuby 1.4.7
Connect from Java to MySQL using Eclipse
I want to display an error message when registering in the database
ERROR 2002 (HY000) when starting MySQL: Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2)
[Java] When dealing with MySQL DB in Doma, insert Batch Insert into one
Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2) error
ERROR 2002 (HY000) when starting MySQL: Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2)
Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock' (2) until resolution.
docker + mysql can't connect / Can't connect to local MySQL server through socket'var / run / mysqld / mysqld.sock' (2)
[Java] Connect to MySQL
[Java] [SQL Server] Connect to local SQL Server 2017 using JDBC for SQL Server
To connect from Spring to MySQL on virtual server (unsolved)
Connect to MySQL 8 with Java
[Android] Connect to MySQL (unfinished)
Connect to Rails server with iPhone
Connect from Java to MySQL using Eclipse
Solution that gives an error when trying to connect to DB (MySQL) in Java
Error response from daemon: conflict: Conflict when trying to create Docker container, so solution
I get an error when I try to use "^" or "$" in ruby ​​regular expression
[Error resolution] Occurs when trying to build an environment for spring with docker
When you want to notify an error somewhere when using graphql-spring-boot in Spring Boot
When using a list in Java, java.awt.List comes out and an error occurs
I want to send an email in Java.
Connect to Aurora (MySQL) from a Java application
Unable to connect to chromedriver error when running SystemSpec
[Rails] Solution when migration error occurs in acts-as-taggable-on
When deploying to Heroku, OpenApp causes an error
How to solve an Expression Problem in Java
A solution to an error that makes you angry that you are not following the MySQL default setting ONLY_FULL_GROUP_BY in a production environment and it is not unique.
An embarrassing story that was treated as the same day when trying to compare dates on 3/31 and 4/1 [Java / Calendar]
I got an error when trying to install sbt to build a Scala development environment
A story that did not work when trying to handle events in Notification Center
What to do when an error occurs in rails db: migrate ((StandardError: An error has occurred, this and all later migrations canceled :))
Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2) error
What to do when an error (StandardError: An error has occurred, this and all later migrations canceled:) appears in rails db: migrate
When you want to dynamically replace Annotation in Java8
twitter4j java Store the searched tweets in DB (MySQL).
About the error that occurred when adding the column name in rails (rails db: migrate, rails db: rollback, add)
How to batch initialize arrays in Java that I didn't know when I was a beginner
When trying to insert a specific gem (levenshtein) with Docker, an error occurred without ruby-dev
After setting database to mysql, bundle install causes an error
Resolve CreateProcess error = 206 when running Java in a Windows environment
Solution for errors that occur when upgrading to Rails 5.2 series
Connect to multiple MySQL instances with SSL enabled in JDBC
What happened in "Java 8 to Java 11" and how to build an environment
How to specify db when creating an app with rails
Things to be aware of when writing code in Java
How to dynamically switch JDK when building Java in Gradle
An error occurs when codedeploy-agent is installed in Ubuntu Server 20.04
Show detailed error in Logger when running Java on server
[Docker] The story that an error occurred in docker-compose up
[Rails] What to do when the error No database selected and Unknown database appears in db: migrate
[Programming beginner] What to do when rails s becomes an error in the local development environment
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do if an error occurs when doing npm install axios in React + Typescript project