1

how to connect mysql database to desktop java application using jdbc ? the environment is ubuntu 12.04 Lts i tried so many ways but all of them throw an exception on executing

 Class.forName("com.mysql.jdbc.Driver");

the exception say :

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

the full code is :

import java.sql.*;

public class CRUDForGoods {
    private Connection connection ;
    public Vector<GoodsStore> goods ;

    public CRUDForGoods(){
        try{
           DriverManager.registerDriver(new JdbcOdbcDriver());
            connection = DriverManager.getConnection("jdbc:odbc:dbName","root", "root");



        }
           catch(Exception ex) {
            System.out.println("##connection");
            ex.printStackTrace();
        }
    }
2
  • My goodness why are you using reflection? Commented Sep 8, 2012 at 14:08
  • 2
    Is mysql-connector.jar on your classpath? Commented Sep 8, 2012 at 14:08

1 Answer 1

1

com.mysql.jdbc.Driver not found while executing the code.

You need mysql connector to get it run (the jar includes com.mysql.jdbc.Driver). You can find it here

Download and include the jar file in your classpath.

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

Comments

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.