4

I got these errors for my Java program. I have already put the mysql-connector-java-5.1.14-bin.jar inside my classpath. How to solve this?

HSystemRDB.java:144: package com.mysql.jdbc does not exist
    Driver driver = new com.mysql.jdbc.Driver();
                                      ^
HTestClassRDB.java:99: package com.mysql.jdbc does not exist
        DriverManager.registerDriver(new com.mysql.jdbc.Driver());

The code:

    String url = "jdbc:mysql://wire:3306/h?user="+pSystemRDB.USERNAME+"&password="+pSystemRDB.PASSWORD;
    Connection con;
    Statement stmt;
    String query1 = "Delete from dbase";
    String query2 = "Delete from id";


    try {
        DriverManager.registerDriver(new com.mysql.jdbc.Driver());
    } catch (Exception e) {
        System.out.println("Class Not Found Exception:");
        System.out.println(e.getMessage());
    }
2
  • Well, it's probably not lying. Are you sure the mysql connector is in your classpath? Have you read this? dev.mysql.com/doc/refman/5.1/en/… Commented Dec 8, 2010 at 8:22
  • 1
    He could try String s = "java" + "mysql"; ... :-) Commented Dec 8, 2010 at 10:59

3 Answers 3

7

You need to download the mysql package from: here and place it inside the library, i'll edit the excact steps in a few min

this is the correct syntax to connect to a database:

try
{
  // create a java mysql database connection
  String myDriver = "org.gjt.mm.mysql.Driver";
  String myUrl = "jdbc:mysql://localhost/test";
  Class.forName(myDriver);
  Connection conn = DriverManager.getConnection(myUrl, "root", "");

  // your prepstatements goes here...

  conn.close();
}
catch (Exception e)
{
  System.err.println("Got an exception! ");
  System.err.println(e.getMessage());
}

Hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

useful and understandable!!
7

You need to add MySQL Driver in your classpath for that , and import appropriate classes your source .

Please refer to this basic tutorial , article

1 Comment

Already added the mysql *.jar to my classpath. Am I missing something inside the code?
0

It seems that you do not have jar file to connect database. You can download mysql-connector-java-3.1.12.jar.

Please, download it and place it in the lib folder of your web application. This should fix your problem.

If you have any other problem, you can refer this tutorial for steps to connect MySQL using JDBC

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.