Connection conn = DriverManager.getConnection(url, username, password); DatabaseMetaData metadata = conn.getMetaData(); String version = metadata.getDatabaseProductVersion(); System.out.println("Database version: " + version);
Connection conn = DriverManager.getConnection(url, username, password); DatabaseMetaData metadata = conn.getMetaData(); ResultSet tables = metadata.getTables(null, null, null, new String[] {"TABLE"}); while (tables.next()) { String tableName = tables.getString("TABLE_NAME"); System.out.println("Table name: " + tableName); }This code connects to a database and retrieves the metadata for all tables in the database. It then iterates through the ResultSet to print out each table name. The getMetaData() method is part of the java.sql package, which is included in the Java Standard Edition (SE) library.