Reputation: 1
I'm trying to connect my Java app to MariaDB database. MariaDB is properly installed and it can be used with DBeaver without any issue. However, my Java app cannot connect to the database. Here is how my project looks like. I have imported the mariaDB connector to the project properly. Am I doing something wrong? I can't figure out what could be the problem. Please, can anyone can help regarding this issue?
Specs: Mac IDE Eclipse JDK17 MariaDB v11.1.2 MariaDB connector 3.2
enter image description here enter image description here
I use to work with Java19, so I downgraded to 17 but the error is the same. I have tried many restart the IDE after importing the MariaDB connector jar file. I have followed many tutorials but it didn't solve the issue.
Upvotes: -1
Views: 793
Reputation: 76799
Adding mariadb-java-client
as dependency provides the driver ...
dependencies {
implementation("org.mariadb.jdbc:mariadb-java-client:3.5.1")
}
Upvotes: 0
Reputation: 1
I found the issue I was using the wrong file : mariadb-java-client-3.2.0-sources.jar I use this instead : mariadb-java-client-3.2.0.jar It's working now
Upvotes: 0
Reputation: 9
the problem is propably the string at line 14, try this .
String url = "jdbc:mariadb://localhost:3306/your_database_name";
String username = "username";
String password = "password";
try {
Class.forName("org.mariadb.jdbc.Driver");
// Create a database connection
Connection connection = DriverManager.getConnection(url,username,
password);
}catch (ClassNotFoundException e) {
e.printStackTrace();
}catch (SQLException e){
e.printStackTrace();
}
Upvotes: 1
Reputation: 577
You should verify that the jdbc driver jar is in fact on the class path. One trick you can use is to simply print out the classpath at the start of program execution. If it is on your classpath, I'd be very surprised. If it is not, then you now have a line of investigation: How do you ensure that the driver jar is on your classpath when running within Eclipse?
Upvotes: 0