简体   繁体   中英

How to connect java using eclipse with MySQL database

I got the error

Error:java.sql.SQLException: The server time zone value 'Malay Peninsula Standard Time' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the server timezone configuration property) to use a more specific time zone value if you want to utilize time zone support. java.lang.NullPointerException

I tried changing my computer's time with our local timezone but still the same error.

I tried adding my connection:

"jdbc:mysql://localhost/db?useUnicode=true&useJDBCCompliatnTimezoneShift=true&useLegacyDatetimeCode=false","root",""

still no work and i got the error:

Error:java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';useJDBCCompliatnTimezoneShift=true&useLegacyDatetimeCode=false'. java.lang.NullPointerException

My connection string is:

Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/raqs","root","");

Fix your typo. It's 'compliant', not 'compliatn'. Just like the error says.

To solve my problem:

I have only added serverTimezone=UTC to my URL. And to be very careful in declaring a query which is case sensitive. And make sure in declaring variables in String or in Int and etc.

My codes worked well already and successfully connected my database to the eclipse ^_^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM