Hello, my code is

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

public class LoadDriver {
    public static void main(String[] args) {
	
		Connection conn = null;
		
		try {
            // The newInstance() call is a work around for some
            // broken Java implementations

            Class.forName("com.mysql.jdbc.Driver").newInstance();
        } catch (Exception ex) {
			System.out.println("daaaaaaaaaa");
            // handle the error
        }

        try {
			
			conn =  DriverManager.getConnection("jdbc:mysql:rootkit", "root", "1231");

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

    }
}

the compilation is ok but when i try to run it, it displays:

C:\Users\0717857\Desktop\JDBC>java -classpath . LoadDriver
daaaaaaaaaa
SQLException: No suitable driver found for jdbc:mysql:rootkit
SQLState: 08001
VendorError: 0

This means that the line "Class.forName("com.mysql.jdbc.Driver").newInstance();" is not working.any idea for why this happens? thank you

Recommended Answers

All 3 Replies

Reread the MySQL Connector/J documentation and redo the URL accordingly.

Thanks for the reply, i'll surely read it after this. however, i think the driver is not even loaded since it display the "daaaaaaaaaa" which is in the Exception and this means that the "Class.forName("com.mysql.jdbc.Driver").newInstance();" is not working, isn't it?

No. That would be a ClassNotFoundException. You are getting a NoSuitableDriver, which means it does not recognise that URL as a MySQL URL and so does not know to use the loaded MySQL driver, so it can only complain that it doesn't have any driver that will work with that URL.

Be a part of the DaniWeb community

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