Minimum Java Project JavaSe-1.8.
Adding MariaDB Connector/J 2.7.3 to Eclipse 2021-06:
- Download MariaDB Connector/J 2.7.3 (stable) from https://downloads.mariadb.org/connector-java/2.7.3/
- Put JAR file in [Workspace] -> [project_name] -> lib (create folder lib)
- Right click on Package Explorer -> [project_name] -> Properties
- Java Build Path -> Library -> Add External JARs, point it to [Workspace]/[project_name]/lib/mariadb-java-client-2.7.3.jar
- Click Apply and Close
Example code to access MariaDB database
package com.dedetok;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class TesCon {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
String muser = "my_user";
String mpass = "my_password";
String murl = "jdbc:mariadb://localhost:3306/my_database_name";
Class.forName("org.mariadb.jdbc.Driver");
Connection connection = DriverManager.getConnection(murl, muser, mpass);
System.out.println("ok");
}
}
No comments:
Post a Comment