0
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?

asked Apr 26, 2018 at 6:39
6

2 Answers 2

1
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";
answered Apr 26, 2018 at 7:58
Sign up to request clarification or add additional context in comments.

1 Comment

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日).
0

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

5 Comments

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.
Please share the stack trace.
SLL part is just warning
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.
Please refer to the URL provided link[link]

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.