一、jdbc连接mysql代码示例
public class TestConnector {
final static String USER = “root”;
final static String PASSWORD = “wjt86912572”;
final static String URL = “jdbc:mysql://bigdata121:3306/metastore?useSSL=false&serverTimezone=UTC&useUnicode=true”;
//这是 mysql.connector 在8.x版本中新驱动,com.mysql.jdbc.Driver在此版本中已弃用
final static String DRIVER = “com.mysql.cj.jdbc.Driver”;
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
//加载驱动类
Class.forName(DRIVER);
//获取连接对象
connection = DriverManager.getConnection(URL, USER, PASSWORD);
//获取连接的代理对象,用于传递sql请求
statement = connection.createStatement();
boolean result = statement.execute("show databases;");
resultSet = statement.getResultSet();
//res