import java.sql.*;
public class CheckTableExistence {
public static void main(String[] args) throws SQLException {
String url = "jdbc:mysql://localhost:3306/mydatabase"; // MySQL服务器地址及数据库名称
String username = "root"; // MySQL登录用户名
String password = "password"; // MySQL登录密码
try (Connection conn = DriverManager.getConnection(url, username, password)) {
DatabaseMetaData metaData = conn.getMetaData();
ResultSet rs = metaData.getTables(null, null, "tableName", new String[]{});
if (!rs.next()) {
System.out.println("表不存在");
} else {
System.out.println("表存在");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
标签:Java,String,mysql,resultset,System,MySQL,password
From: https://www.cnblogs.com/Twittery/p/17982750