I tried using the below function in my swing application and I got the error message in the title. This was strange to me as when running the exact same code on the Eclipse IDE, instead of NetBeans, the function executed perfectly. I believe I've installed the driver correctly as in the services tab I can see and access the data inside the MySQL table via a created Driver.
public void insert(String Item, String Size, int Price, String Details){
try{
con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/ddApp", "root", "****"); //stars replacing password
ps = con.prepareStatement("INSERT INTO ddApp.currentTable (item, size, price, description) VALUES (?, ?, ?, ?) ");
ps.setString(1, Item);
ps.setString(2, Size);
ps.setInt(3, Price);
ps.setString(4, Details);
ps.executeUpdate();
}catch(Exception ex){
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
JDBC drivers 'exist', or not (as in, a JDBC url 'works' or not, depending on whether the driver exists), simply by being on the classpath. Whether you see it in any other tab in netbeans is irrelevant: When netbeans 'runs' your app, it's just invoking java.exe
with some classpath.
That classpath needs to include the mysql-jdbc.jar driver. If it does, that error goes away. If it doesn't, you get that error.
If you're using build systems like maven or gradle, as long as you've set up the dependency properly (you've added the dep on mysql-jdbc, and its in the usual 'this is needed at compile time and run time' configuration which is the default), then as long as you've set up your IDE to use that build config as project basis, everything just works.
If that's not what you did, ensure mysql is on the classpath.
It doesn't ordinarily have to be - during compilation you don't need it at all. dependencies (jar files, generally) need to be there either [A] only when compiling, not needed at runtime (example: Project Lombok), [B] only when running, not needed to compile (those'd be plugins that simply implement some service API). Mysql-jdbc is one of those, or [C] (the default) needed for both. Hibernate, Guava, logging frameworks - most of your dependencies are this kind.
So, this is a category [B]. You need to tell netbeans to ensure mysql is on the command line. An easy way out is to just treat it as a [C] - your code could be compiled without it, but it doesn't hurt at all if that mysql-jdbc jar is on the classpath when netbeans is compiling your code. That means: Whatever mechanism netbeans has to add a jar dependency, use that (I can't really tell you - it depends on how you've set up the project).