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
                    Class.forName(driverName);
               
// 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);
             con.close();
             
        } catch (ClassNotFoundException e) {
            );
        } }
    catch (SQLException e) {j);
   
dajoebombAsked:
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.

CEHJCommented:
You need to put the driver jar in the Tomcat lib directory
0
dajoebombAuthor Commented:
Hi CEHJ,
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?
0
dajoebombAuthor Commented:
Please someone help me, I am actually going insane!!!
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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

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

Am i missing anything or have anything in the wrong place?
Thanks once again CEHJ
0
CEHJCommented:
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
0
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?
0
rrzCommented:
>String url = "jdbc:mysql://localhost/test?autoReconnect=true";  
Maybe try adding standard port.
String url = "jdbc:mysql://localhost:3306/test?autoReconnect=true";    
0
CEHJCommented:
Something like
<applet code="org.me.hello.MyApplet" archive="HelloApplet.jar,mysql-connector-java-5.0.4-bin.jar" width="400px" height="400px"/> 

Open in new window

0

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!
0
CEHJCommented:
The db must be on the same host as the applet's loaded from or it will need to be signed
0
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
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.