Dates with no time or timezone component in Java/MySQL
I concluded that the best way in my current application (a simple utility using jdbc directly) was to insert directly as a string. For a bigger Hibernate app I might bother to write my own user type. Can't believe someone hasn't already solved this problem in some publicly available code though...
Store and retrieve a date in MySQL without any timezone information using MySQL Connector/J 8.0
In the past I've used this trick to make sure that the effective server time zone is the same as the client time zone:
String connectionUrl = "jdbc:mysql://localhost:3307/mydb?useUnicode=true"
+ "&serverTimezone=" + ZoneId.systemDefault().getId();
System.out.println(connectionUrl);
// jdbc:mysql://localhost:3307/mydb?useUnicode=true&serverTimezone=America/Denver
Connection conn = DriverManager.getConnection(connectionUrl, myUid, myPwd);
MySQL JDBC Driver 5.1.33 - Time Zone Issue
Apparently, to get version 5.1.33 of MySQL JDBC driver to work with UTC time zone, one has to specify the serverTimezone
explicitly in the connection string.
jdbc:mysql://localhost/db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
Related Topics
How Can a Java Program Get Its Own Process Id
How to Read and Write Excel File
How to Sort by Two Fields in Java
Difference Between Static Methods and Instance Methods
403 Forbidden With Java But Not Web Browser
Resizing Issue With Canvas Within Jscrollpane Within Jsplitpane
Different Ways of Loading a File as an Inputstream
In Java Streams Is Peek Really Only For Debugging
Occurrences of Substring in a String
When Does Static Class Initialization Happen
Java: Date from Unix Timestamp
Why Is Volatile Used in Double Checked Locking
Swing: Link Toggle Buttons Together With a Button Group, Along With Corresponding Menu Items
How to Print Color in Console Using System.Out.Println
How to Tell Gradle to Use Specific Jdk Version
Are Getters and Setters Poor Design? Contradictory Advice Seen