-1

I can't connect to my SQL Database, Error: java.sql.SQLException: No suitable driver found for jbdc:mysql://localhost:3306/[DBName]?user=root&password=[Password]

This is my used Class-Code:

package plugin.components;

import java.sql.*;

import org.bukkit.entity.Player;

public class DatabaseManager {

    public static void connectionTest(Player p, String url) throws ClassNotFoundException {
        Class.forName("com.mysql.jdbc.Driver");
        try(Connection conn = DriverManager.getConnection(url)){
            
            
            if(conn != null ) {
                Message.send(p, "information", "§aConnection successfull.");
            }else {
                Message.send(p, "warning", "§4Connection Failed.");
            }
            
            
            
    
        }catch(SQLException ex) {
            Console.sendMassage(Console.getMessageByID("sqlerror"));
            Console.sendMassage("§4Error: §e" + ex);
        }
        
    }
    
    public static void requestInformation(String url,  String username, String password) {
        
        
        
    }
}

The infomations for Login are in a another class

Vishal
  • 428
  • 4
  • 19
  • 2
    Does this answer your question? [The infamous java.sql.SQLException: No suitable driver found](https://stackoverflow.com/questions/1911253/the-infamous-java-sql-sqlexception-no-suitable-driver-found) – Vishal Jul 14 '20 at 15:59

2 Answers2

0

You should add driver jar to classpath. If you are using maven add

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.20</version>
</dependency>
Mladen Savić
  • 462
  • 5
  • 10
  • I use only Java and how to add this what you mean? – dragomann12 Jul 14 '20 at 16:00
  • Use this steps (https://www.javahelps.com/2015/08/add-mysql-jdbc-driver-to-eclipse.html) to add to classpath in Eclipse. If you are using cmd to start your application use this https://javarevisited.blogspot.com/2012/10/5-ways-to-add-multiple-jar-to-classpath-java.html – Mladen Savić Jul 14 '20 at 16:04
0

I have used this for a project of mine. To make it work you need to install the jar file that is the sql connector.

Then add it to external archives. If you use eclipse right click on the project :

Build Path > Add External Archives.

and browse the jar file. you can find the jar file online or you can use the following link: file .jar download

And if tou need an example of how to use the database : I have an example right here in the same repository.

Dharman
  • 21,838
  • 18
  • 57
  • 107
Anass ABEA
  • 434
  • 3
  • 11