i'm working on netbeans and want to access my database using this code:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class connect {

     * @param args
    public static void main(String[] args) {
        try {
        catch (Exception ex) {
            System.out.println("error \n");

        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/university", "root", "");
            // Do something with the Connection
            Statement stmt = null;
            ResultSet rs = null;
            stmt = conn.createStatement();
            rs = stmt.executeQuery("SELECT * FROM student");
            int numCols = rs.getMetaData().getColumnCount ();
            while ( rs.next() ) {

                     for (int i=1; i<=numCols; i++) {
                         System.out.print("<td>" + rs.getString(i) + "</td>" );
              }  // end for
            }  // end while

        } catch (SQLException ex) {
            // handle any errors
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());


everytime i run the program i get this message:

SQLException: No suitable driver found for jdbc:mysql://localhost:3306/university
SQLState: 08001
VendorError: 0

The code is working very well on Eclipse ... but i cant get it running on netbeas even though i added the needed driver for it to run and it says that its already connect.

Recommended Answers

All 6 Replies

Error message is self-explanatory, you missing JDBC driver Connector/J or if you have it you did not added to your project CLASSPATH

yeah i think i might missed adding the class path ... do you know how it may be added?
The driver is added for sure .. just did that a moment ago.

If it is web project you should just simply drop the JAR into WEB_PROJECT/WEB-INF/lib directory and IDE should automatically pick-up the change.
In the case that driver is not recognised or you working on different type of project, GUI/mobile or any other project, right click on the project, select PROPERTIES, in the pop-up window in CATEGORIES (left side listing) select Libraries, on the right press Add JAR/Folder and navigate to place where is the driver.
Otherwise you may try to follow this obscure NetBeans tutorial

Oh many thanks to you !! .. it worked well as u described.

So you able to retrieve your data now?

yep .. the queries i'm writing are retrieving data now ..
i'm making a small database for a supermarket .. its a small project for my database course in uni .. and the example i provided up is for only testing the connection.

Thanks a lot for you help!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.