I have tried a lot for JDBC using mysql but none of them work....
Can anyone help me how to get this work....

import java.sql.Connection;
import java.sql.DriverManager;

public class Main {
  public static void main(String[] argv) throws Exception {
    String driver = "com.mysql.jdbc.Driver";
    String connection = "jdbc:mysql://localhost:3306/abc";
    String user = "root";
    String password = "password";
    Class.forName(driver);
    Connection con = DriverManager.getConnection(connection, user, password);
    if (!con.isClosed()) {
      con.close();
    }
  }
}

I have downloaded com.mysql.jdbc.driver file.
included in my classpath but still i am getting the classnotfound error for "com.mysql.jdbc.Driver'.

Then you have not "included it on your classpath" properly. How did you "include it on your classpath" and how, exactly are you executing this code.

I already came with solution....
Their was nothing wrong.....only a bit mistake in the way of using classpath....
By the way thanks for your suggeestions!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.