Reputation: 5
Im trying to connect to a database called "CompanyCSV" using JDBC but when i try to connect it says "No suitable driver found for jdbc:mariadb://localhost:3306/companyCSV", here's the code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connectar {
public static void main(String[] args) {
String url = "jdbc:mariadb://localhost:3306/companyCSV";
String user = "root";
String passwd = "root";
try (Connection con =
DriverManager.getConnection(url, user, passwd);){
System.out.println("Connexió exitosa a la base de dades!");
} catch (SQLException e) {
System.err.println("Error d'establiment de connexió: " + e.getMessage());
}
}
}
Upvotes: 0
Views: 2103
Reputation:
To connect your Java app to a MariaBD server via JDBC, you need to obtain a JDBC driver.
If using Maven as your dependency manager, you have to add the following dependency to your pom.xml file. This will download the MariaDB driver for your project.
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.2</version>
</dependency>
Upvotes: 2
Reputation: 397
You need to load the driver first. I never used MariaDB but for most databases you need to do something like
Class.forName("<class implementing the driver">);
You'll surely find some examples on the MariaDB homepage.
Upvotes: 0