0
package cs352hw;
import java.sql.Connection;
import java.sql.DriverManager;
public class Main {
   public static void main(String[] args) {
    // TODO code application logic here
      DB db = new DB();
            Connection conn=db.dbConnect(
              "jdbc:mysql://dijkstra.ug.bcc.bilkent.edu.tr",
              "",
              "");
      }

}


      //This Class is taken from http://www.java-tips.org/other-api-tips/jdbc/how-to-connect-mysql-server-using-jdbc.html
class DB
   {
    public DB() {}

    public Connection dbConnect(String db_connect_string,
      String db_userid, String db_password)
    {
            try
            {
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                    Connection conn = DriverManager.getConnection(
                      db_connect_string, db_userid, db_password);

                    System.out.println("connected");
                    return conn;

            }
            catch (Exception e)
            {
                    e.printStackTrace();
                    return null;
            }
    }
};

Hey guys my classes are given above

I am new at jdbc stuff

Please help me I am getting run time error such that

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Thanks for any advice

Note: I don't know How to put the jar file into my classpath and bind it dynamically :S

7
  • 2
    You have to put the MySQL JDBC library (jar file) in the classpath of your program at runtime. Commented Apr 8, 2011 at 20:42
  • dev.mysql.com/downloads/connector/j Commented Apr 8, 2011 at 20:44
  • i've put the jar file into every folder in my project but still gives the same error :( Commented Apr 8, 2011 at 20:52
  • 2
    You should remove your password from your post. Commented Apr 8, 2011 at 20:54
  • 1
    Actually you will need to change the password on that server, if it's something that matters, as we can all see the password by looking at the revision history. :-/ Commented Apr 8, 2011 at 21:25

1 Answer 1

1

You need to download the MySQL Connector/J and add the .jar file in your application

Add the jar file in the WEB-INF/lib, if its a web-app, else in the lib folder of your project and then try to run

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

4 Comments

I've tried, I created a new folder, but I couldn't make it work :(
NetBeans 6.9.1 There are test, src, nbproject, build folders under my project folder
You need to right click on the project name in the project tab the go to Properties-> Libraries -> Press Add Jar/Folder... Browse and select your jar...and click OK...and build and re-run
thank you so much :) This was a too stupid question as programmer but I think everbody makes such mistakes :)

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.