先下載connector/j
Download
挑一個新版本來用, 在這裡是 2.6.1
eclipse新開一個java project
project右鍵選properties
左邊選Java Build Path, 右邊選Libraries, 點Add External JARs
選剛剛下載的connector, 選完成
開一個class叫MariaDB
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class MariaDB {
private static final String dbClassName = "org.mariadb.jdbc.Driver";
private static final String CONNECTION = "jdbc:mariadb://localhost:3306/dataTable";
public static void main(String[] args) throws ClassNotFoundException, SQLException {
System.out.println(dbClassName);
Class.forName(dbClassName);
Properties p = new Properties();
p.put("user", "USERNAME");
p.put("password", "PASSWORD");
Connection c = DriverManager.getConnection(CONNECTION, p);
System.out.println("It works !");
c.close();
}
}
出現 It works !就成功囉