i have installed mysql , and JDK . I wrote the following code to test jdbc . But it didnt work

public class Test {
  public static void main(String[] args) {
    try {
      Class.forName("root.mysql.jdbc.Driver").newInstance();
      System.out.println("Good to go");
    } catch (Exception E) {
      System.out.println("JDBC Driver error");  
    }
  }
}

its printing
JDBC Driver error


But when i script in PhP , i can connect and store in db using MySQL.

Did you downloaded Connector/J and pointed your IDE or set a CLASSPATH to location of this JAR file?

Try including E.printStackTrace(); as well. You are discarding the more detailed info from the exception.

I agree with Peter though. You probably don't have that jar on your classpath.

as far as i know, mysql driver class is "mysql.jdbc.Driver" without "root" as in your code,
and you don't have to call newInstance() method,
try to change your code like this:

public class Test {
  public static void main(String[] args) {
    try {
      Class.forName("mysql.jdbc.Driver");
      System.out.println("Good to go");
    } catch (Exception E) {
      System.out.println("JDBC Driver error");  
    }
  }
}

regards,

Did you downloaded Connector/J and pointed your IDE or set a CLASSPATH to location of this JAR file?

Well is it a kinda of config we have to do to establish the connection.
I thought there wasnt any thing else to do

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.