Reputation: 145
I would like to use my MariaDB database but I get the error message:
java.lang.ClassNotFoundException: org.mariadb.jdbc.Driver
My pom.xml includes:
<dependencies>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.1.7</version>
</dependency>
</dependencies>
Also I have downloaded the file mariadb-java-client-2.4.1-sources.jar
and placed it into WEB-INF/lib.
Database.java
package ch.yourclick.zt;
import java.sql.*;
public class Database {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
// Ensure we have mariadb Driver in classpath
Class.forName("org.mariadb.jdbc.Driver");
// create our mysql database connection
String host = "localhost";
String dbname = "zt_productions";
String url = "jdbc:mariadb://" + host + "/" + dbname;
String username = "root";
String password = "test";
Connection conn = DriverManager.getConnection(url, username, password);
// our SQL SELECT query.
// if you only need a few columns, specify them by name instead of using "*"
String query = "SELECT * FROM users";
// create the java statement
Statement st = conn.createStatement();
st.close();
}
}
I also tried it with Class.forName("org.mariadb.jdbc.Driver").newInstance();
.
No matter what I try, I always get the same error message. Any help would be appreciated.
Upvotes: 2
Views: 5168
Reputation: 9
I had this Problem myself: the solution was quite simple... MariaDB is basically still MySQL. In the Url you are using to connect to the Database (jdbc:mariadb://localhost:3306) you can therefore just use jdbc:mysql://localhost:3306 <- i just replaced mariadb with mysql. It is still running on a mariadb server but it works so dont change it ;)
Upvotes: 0
Reputation: 5421
You are using the wrong jar file. The source won't help you out.
Instead of mariadb-java-client-2.4.1-sources.jar
, try using mariadb-java-client-2.4.1.jar
.
Upvotes: 1