Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


In NetBeans connect to mySQL table

Posted on 2010-11-16
Medium Priority
Last Modified: 2013-11-23
I get this error when I try to connect to my mySQL db in Netbeans on a mac OSX 10.6.5

It worked fine on my ibm laptop
Question by:jdiebold
  • 7
  • 3

Author Comment

ID: 34150798
I get this error:

Class Not Found Exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
BUILD SUCCESSFUL (total time: 1 second)


Author Comment

ID: 34150809
This is my code:

 * To change this template, choose Tools | Templates
 * and open the template in the editor.

package coffeebreak;

import java.sql.*;

 * @author PuckHead
public class CoffeeBreak {

 * @param args the command line arguments
    public static void main(String[] args)

            String connectionUrl = "jdbc:mysql://localhost:8889/coffeebreak?" +

            Connection con = DriverManager.getConnection(connectionUrl);

            Statement stmt = null;
            ResultSet rs = null;

            //SQL query command
            String SQL = "SELECT * FROM coffees WHERE PRICE between 7.00 and 8.00";

            stmt = con.createStatement();
            rs = stmt.executeQuery(SQL);
LVL 92

Expert Comment

ID: 34150879
you need to add the mysql jar to your classpath
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 34150976
Awesome!  How do I do that on a mac?
LVL 92

Expert Comment

ID: 34150998
add it to your netbeans build path

Author Comment

ID: 34151010
I have the mysql-connector-java-5.1.12.zip

included in my Libraries folder of my project in Netbeans

I guess i though that was adding it to the class path?

Author Comment

ID: 34151058
Is the classpath listed under properties > Misc > Ant?
LVL 92

Assisted Solution

objects earned 400 total points
ID: 34151091
you need to unzip it and add the include *jar* to your libraries (not the whole zip)

Accepted Solution

jdiebold earned 0 total points
ID: 34324655
I found the answer that I was looking for here:


Re: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver on Mac OS X Leopard
Posted by: Mitch Graves ()
Date: February 09, 2008 01:29AM

I have the answer. After a long dig through Google, I finally found a bit of information that solves my problem on Leopard and Tiger. I found that the CLASSPATH doesn't work at all (at least for me) and all that needs to be done is to copy the mysql JDBC connector to /Library/Java/Extensions. As soon as I did that, my java program could connect to my MySQL database and I was off and running.

Author Closing Comment

ID: 34367406
The CLASSPATH is the common answer here but it did not work. Only when I added the mysql JDBC connector to /Library/Java/Extensions did it work.

His last post may have hinted at that but not at enough detail to show me how to fix it as a novice.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question