1

i'm trying run code

public static Connection getConnection() throws SQLException{
        try {
            Class.forName("com.mysql.jdbc.Driver");
            cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull [root on Default schema]");
        } catch (ClassNotFoundException | SQLException e) {
            JOptionPane.showMessageDialog(null,e.toString());
        }
        return cn;
    }

but i get the exception: enter image description here

with the dialog:

enter image description here

I have added the divier :mysql-connector-java-5.1.36-bin.jar in this project. What am I doing wrong?

2
  • You run it from eclipse? Have you add it as library? See stackoverflow.com/questions/3280353/… Commented Jul 18, 2015 at 14:16
  • 2
    The JAR isn't in the CLASSPATH. Put it there and find your next problem. Commented Jul 18, 2015 at 14:18

1 Answer 1

1

Add mysql connector jar to your project classpath.

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.6</version>
</dependency>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.