-3

my code not work java and jsp plz help me

public class DbConnect {
    Connection conn = null;
    ResultSet rst;
    java.sql.Statement stmt;
    String url="jdbc:mysql://localhost:3306/";
    String dbName="teljo";
    String driver="com.mysql.jdbc.Driver";
    String userName="root";
    String password="";

    public Connection getConnect(){
        try {
            Class.forName(driver).newInstance();
            System.out.println("driver loaded sucessfully");
            conn=DriverManager.getConnection(url + dbName,userName,password);
            System.out.println("connect to the data base");
        }
        catch (ClassNotFoundException ce) {
            System.out.println("driver loading failed"+ ce);
        }
        catch (Exception e) {
            System.out.println("error in connection to database");
        }
        return conn;
    }
}

this is my connection code db class. the mysql connection notconnect what is do? i using eclipse IDE, output is this

 driver loading failedjava.lang.ClassNotFoundException: com.mysql.jdbc.Driverjava.lang.NullPointerException
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
arun sasi
  • 1
  • 4
  • If your error message truly says that class `com.mysql.jdbc.Driverjava.lang.NullPointerException` is not found, then your `driver` variable got updated somewhere in code you haven't shown. – Andreas Jan 08 '17 at 06:11
  • 2
    *Unrelated:* Do not put `ResultSet` and `Statement` in your `DbConnect` class. They should be local variables where they are used. It's very rare for those to be fields. – Andreas Jan 08 '17 at 06:12

1 Answers1

0

enter image description here

Please add external MySQL Connector/J to your project. These would solve the problem.

Link for downloading mysql jdbc jar: https://dev.mysql.com/downloads/connector/j/

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Never ever link to Google drive when there is an official download site; I have edited your question to reflect that. I have also removed the ancient version you mentioned. – Mark Rotteveel Jan 08 '17 at 08:52
  • but i import the jar but not work why . netbeans the code work but eclipse the code not work that is problem – arun sasi Jan 27 '17 at 11:25