-3

I am trying to connect to my coffee database to insert data but every-time I run the code it says

No suitable driver found for jdbc:derby://localhost:1527/coffeeZone

iv'e tried using this Class.forName("dbc:derby://localhost:1527/coffeeZone"); I also have the mysql jdbc driver on my mac

    String query="INSERT INTO `coffeeZone`.`branch` (`branch_Num`, `admin_id`, `Street`, `Nieghbourhood`) VALUES ('?', '?', '?', '?');";

          try{

      PreparedStatement ps;
      String f="jdbc:derby://localhost:1527/coffeeZone [coffee on COFFEE]";

      connection = DriverManager.getConnection(
            f, "coffee", "1234"); 
       ps=connection.prepareStatement(query);
        ps.setString(1, bno);
        ps.setString(2, strt);
       ps.setString(3, nbh);
        ps.setString(4, ci);
   if  (ps.executeUpdate()>0){


                    JOptionPane.showMessageDialog(null, "Complete! a new branch is added !");
               }else
               {
                   JOptionPane.showMessageDialog(null, "User already exists");
               }

    }        catch (SQLException ex) {
           JOptionPane.showMessageDialog(null,ex);
    }                                       

    }
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
ninaya
  • 33
  • 5

1 Answers1

1

Looks like you'll need to call Class.forName("com.mysql.jdbc.Driver") prior establishing your connection, based on this connection string: jdbc:mysql://localhost/dbname.

Edit: If you're using Derby, you need this: Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); (https://db.apache.org/derby/docs/10.4/devguide/cdevdvlp40653.html).

Did you post the exact error that you're getting? It seems strange that the error refers to a MySql connection but the code uses a Derby connection string.

Riaan Nel
  • 2,425
  • 11
  • 18
  • OP stated she is using Derby – Sharon Ben Asher Apr 03 '19 at 06:22
  • 1
    Use of `Class.forName` shouldn't be necessary due to autoloading of drivers (unless this is a web application, but then you shouldn't even be using `DriverManager`). Also given the URL includes a host name and port, the `EmbeddedDriver` is the wrong one. – Mark Rotteveel Apr 03 '19 at 08:57