JDBC
以 MySQL为例:
public static String url = "jdbc:mysql://localhost:3306/test"; public static String name = "root"; public static String pwd = ""; //看用哪个jar包 就用哪个class // Class.forName("com.mysql.jdbc.Driver"); Class.forName("com.mysql.cj.jdbc.Driver"); Connection conn = DriverManager.getConnection(url, name, pwd); PreparedStatement pst = conn.prepareStatement(sql); ResultSet rs = pst.executeQuery();