package dbb;
import java.sql.*;
public class test {
public static void main (String[] args) {
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String pass = "1234";
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver Searched");
conn = DriverManager.getConnection(url, user, pass);
System.out.println("Connection Succeed" + conn);
} catch (ClassNotFoundException e) {
System.out.println("Driver Not Searched");
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
i made this code on java, but there are some errors. for example, enter image description here.
It shows that Driver is already searched, but the connection is still failed.
How can i fix the error?
2 Answers 2
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String pass = "Admin@123";
java.sql.Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver Searched");
conn = DriverManager.getConnection(url, user, pass);
System.out.println("Connection Succeed" + conn);
} catch (ClassNotFoundException e) {
System.out.println("Driver Not Searched");
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
it's working fine in my system with mysql-connector-java-5.1.6jar. Might be This is an issue with the MySql driver.
You can try with below : you might need to explicitly specify timezone in you jdbc url.:
String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
Sign up to request clarification or add additional context in comments.
1 Comment
Mark Rotteveel
Connector/J 5.1.6 is really ancient (it was released in 2008), the latest 5.1.x is 5.1.46 from March 2018, the latest version is 8.0.11 from last week (2018年04月19日).
As already suggested in the comment to use non-ssl connection with latest driver, you should use below code:
package dbb;
import java.sql.*;
public class test {
public static void main (String[] args) {
String url = "jdbc:mysql://localhost:3306/test?useSSL=false";
String user = "root";
String pass = "1234";
Connection conn = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Driver Searched");
conn = DriverManager.getConnection(url, user, pass);
System.out.println("Connection Succeed" + conn);
} catch (ClassNotFoundException e) {
System.out.println("Driver Not Searched");
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
answered Apr 26, 2018 at 6:56
Avinash Sagar
5174 silver badges10 bronze badges
5 Comments
garden lee
still there are problem!! HERE: java.sql.SQLException: The server time zone value '´???¹?±¹ ???ؽ?' 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.
Avinash Sagar
Please share the stack trace.
Piro
SLL part is just warning
garden lee
and this: Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '´???¹?±¹ ???ؽ?' 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.
Avinash Sagar
Please refer to the URL provided link[link]
default
com.mysql.cj.jdbc.Driver; Disable SSL by addinguseSSL=falseto the url. The timezone value looks like something from a SSL handshake.