Solved

In NetBeans connect to mySQL table

Posted on 2010-11-16
10
892 Views
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
0
Comment
Question by:jdiebold
  • 7
  • 3
10 Comments
 

Author Comment

by:jdiebold
ID: 34150798
I get this error:

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


0
 

Author Comment

by:jdiebold
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)
    {

        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            String connectionUrl = "jdbc:mysql://localhost:8889/coffeebreak?" +
                                   "user=admin&password=admin";

            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);
0
 
LVL 92

Expert Comment

by:objects
ID: 34150879
you need to add the mysql jar to your classpath
0
 

Author Comment

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

Expert Comment

by:objects
ID: 34150998
add it to your netbeans build path
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:jdiebold
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?
0
 

Author Comment

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

Assisted Solution

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

Accepted Solution

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

http://forums.mysql.com/read.php?39,195400,195559#REPLY

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.
0
 

Author Closing Comment

by:jdiebold
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.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now