-3

I'm getting a message that:"No suitable driver found for jdbc:mysql://localhost/db" When I run the jar file in dist folder.

I'm using Netbeans,what's confusing me is the fact that,when I execute the program from inside Netbeans ,it works perfectly.

  try {
       Class.forName("java.sql.DriverManager");
       //**please note that I also tried "com.mysql.jdbc.Driver",but same result**
   }
   catch (Exception e) {
       JOptionPane.showMessageDialog(null, e.getMessage());
   }

And my connection string is:"jdbc:mysql://localhost/db"

phpcoderx
  • 570
  • 5
  • 16

1 Answers1

2

First get the appropriate jar, and add it to your class path. Then you can use

Class.forName("com.mysql.jdbc.Driver"); 
DriverManager.getConnection("jdbc:mysql://localhost/test?" +
                               "user=monty&password=greatsqldb");

But you do not use Class.forName("java.sql.DriverManager");.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249