Java and mySQL - ClassNotFoundException: com.mysql.jdbc.Driver

Hi Guys, i've actually been researching this for 11 hours now!! No Joy.
Basically i am creating a program to connect to database and return values - easy
I am using Netbeans and i have mySQL server installed on my local machine, when i run the file in netbeans, it works! It connects to the DB and returns values.

The problem comes when i go outside of Netbeans. If i create a webpage and load the applet through that, it just doesnt work, i get the error
"java.lang.ClassNotFoundException: com.mysql.jdbc.Driver".

In Netbeans i added this file to the Libraries mysql-connector-java-5.1.7-bin.jar. I build and works fine in netbeans, browse to the html, open it and it doesn't work.
I have also uploaded it on a TomCat 5.5 server and i get the same response. I must be doing something wrong.
Please help!!!!

 try {
        Connection con = null;
        try {
// Load the JDBC driver
            String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver
            Statement stmt =null;

                    // MySQL MM JDBC driver
// Create a connection to the database
    /** Creates a new instance of DBUtil */
            String url = "jdbc:mysql://localhost/test?autoReconnect=true";

            String username = "root";
            String password = "password";
            con = DriverManager.getConnection(url,username,password);
        } catch (ClassNotFoundException e) {
        } }
    catch (SQLException e) {j);
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to put the driver jar in the Tomcat lib directory
dajoebombAuthor Commented:
Thanks for your reply,
I am really new to this, i logged on to the server and in /comon/lib/ there was V3.1 of the JDBC driver. I put the V5.1 in anyway, but it doesn't work. Is this the directory that you meant?
dajoebombAuthor Commented:
Please someone help me, I am actually going insane!!!
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Try also putting the jar into the WEB-INF/lib directory of your webapp
dajoebombAuthor Commented:
No I am afraid that doesn't work either.
My folders under ROOT are:

in the body of the index, i have <applet code="" archive="HelloApplet.jar" width="400px" height="400px"/>

Am i missing anything or have anything in the wrong place?
Thanks once again CEHJ
Hang on a minute - are you saying that the applet is doing the JDBC? If so, the driver jar has to be specified in the applet's archive tag too
dajoebombAuthor Commented:
Yeah the applet is doing the JDBC. I later on going to connect clients to the server and recieve information from the database.

How do I specify it in the applets archieve tag?
>String url = "jdbc:mysql://localhost/test?autoReconnect=true";  
Maybe try adding standard port.
String url = "jdbc:mysql://localhost:3306/test?autoReconnect=true";    
Something like
<applet code="" archive="HelloApplet.jar,mysql-connector-java-5.0.4-bin.jar" width="400px" height="400px"/> 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dajoebombAuthor Commented:
Thank you so much, i have now got rid of that problem!!
Would you know it its brought up another error though -com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up

Giving up souds good, but it needs to be done, thanks again CEHJ!
The db must be on the same host as the applet's loaded from or it will need to be signed
dajoebombAuthor Commented:
Yeah, I believe it is, when i do it on my machine where mySQL is running, it returns the same error as when i do it on the Tomcat server.
I read that it might be something to do with pools??
I'm going to look into that next
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.