作者:溪流-ju_506 | 来源:互联网 | 2023-10-11 19:29
驱动依赖
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>8.0.26version>
dependency>
JDBC
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://172.26.250.49:3306/information_schema?useUnicode=true&characterEncoding=ut
String username = "root";
String password = "root1234";
String sql = "select * from information_schema.tables limit 0,10";
Connection connection = DriverManager.getConnection(url, username, password);
PreparedStatement statement = connection.prepareStatement(sql);
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
String col1 = resultSet.getString(1);
String col2 = resultSet.getString(2);
String col3 = resultSet.getString(3);
System.out.println(col1 + "\t" + col2 + "\t" + col3 + "\t");
}
原文链接:https://www.cnblogs.com/wwp666/p/15977195.html