I can connect from the services window but whenever I try to set the code myself on my app it tells me it cannot connect to the database.

Here's my code:

import java.sql.*;
public class LogBook {

    public static void main (String[] args)
       {
           connectToDB();
       }
    // Connect to the Database
    public static void connectToDB() {
        
        Connection connection = null;

           try
           {
               String userName = "manuel";
               String password = "manuel";
               String url = "jdbc:mysql://localhost/logbook";
               Class.forName ("com.mysql.jdbc.Driver").newInstance ();
               connection = DriverManager.getConnection (url, userName, password);
               System.out.println ("Database connection established");
           }
           catch (Exception e)
           {
               System.err.println ("Cannot connect to database server");
           }
           finally
           {
               if (connection != null)
               {
                   try
                   {
                       connection.close ();
                       System.out.println ("Database connection terminated");
                   }
                   catch (Exception e) { /* ignore close errors */ }
               }
           }
    }
}

Not sure what I'm missing here

God I;m stupid, I forgot to add the classpath to my application for the driver

This question has already been answered. Start a new discussion instead.