i am trying to solve this problem by following all steps which is required to connect a Apache Wicket web application to MySQL database.

step1 Right Click on project -> Build Path ->Configure Build Path -> Java Build Path -> Libraries Tab -> Add external jar -> then i browse MySql-Connector-5.0.8 jar file.

step2In program i write down

public static Connection con=null;
public static Connection getConnection()
{
    try
    {
    Class.forName("com.mysql.jdbc.Driver");     
    con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db1", "root", "root");
    }catch(ClassNotFoundException ex){ex.printStackTrace();}
    catch(SQLException e){System.out.println(e);}
    finally{
        try
        {
            con.close();
        }catch(Exception e){}
    }
    return con;
}

but still facing Error the java.lang.ClassNotFoundException: com.mysql.jdbc.Driver now what to do..I need your help

share|improve this question
    
Check whether you have the MySql-Connector-5.0.8.jar under Libraries. If it not there might broken ref , try to add it with the project – San Krish Nov 21 '14 at 11:50
    
yes it is under library..should i add the dependency for MySql in POM.xml..? – Sanjay Kumar Nov 21 '14 at 11:55
up vote 2 down vote accepted

Since you mention your project is a web application I assume that you also use an application server to run your application. Make sure the driver jar is also available to the server. Depending on the platform you may have to change some of the server's configuration as well.

share|improve this answer

Copy the jar file and paste it into your project. It will run perfectively.

share|improve this answer
    
in which directory i should paste it..?because i have already add MySql jar in Library.. – Sanjay Kumar Nov 21 '14 at 11:57
    
in lib folder in your project – user4277917 Nov 21 '14 at 11:58
    
the library is not looking like a folder, it looks like a rar file and i add my jar to library.. – Sanjay Kumar Nov 21 '14 at 12:02
    
if you paste in lib folder then error will be go.i face this type of problems. – user4277917 Nov 21 '14 at 12:04
    
MySql jar is showing in Library folder..but problem has not gone.. – Sanjay Kumar Nov 21 '14 at 12:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.