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?

Community
  • 1
  • 1
duc vu
  • 31
  • 2
  • You run it from eclipse? Have you add it as library? See http://stackoverflow.com/questions/3280353/how-to-import-a-jar-in-eclipse – diufanman Jul 18 '15 at 14:16
  • 2
    The JAR isn't in the CLASSPATH. Put it there and find your next problem. – duffymo Jul 18 '15 at 14:18

1 Answers1

1

Add mysql connector jar to your project classpath.

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.6</version>
</dependency>
Prateek Kapoor
  • 947
  • 9
  • 18