比如这种方式
@Test
public void tableExistSQL() throws SQLException, IOException {
String filePath = MetaTest.class.getResource("/sharding.yaml").getFile();
DataSource dataSource = YamlShardingDataSourceFactory.createDataSource(new File(filePath));
Connection connection = dataSource.getConnection();
String sql = "SELECT COUNT(*) " +
"FROM information_schema.TABLES " +
"WHERE TABLE_NAME = 't_order' ;";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()){
LOG.info("表数量:{}",resultSet.getInt(1));
}
preparedStatement.close();
connection.close();
}