import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.Statement; import java.sql.ResultSet; import java.util.List; import java.util.ArrayList; public class MariaDBMetadata { public static void main(String[] args) { try { Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/DB", "user", "passwd"); DatabaseMetaData dm = connection.getMetaData(); ResultSet r0 = dm.getTables(null, null, "%", null); List tables = new ArrayList(); while (r0.next()) { tables.add(r0.getString(3)); } r0.close(); System.out.println("Added tables [" + tables.size() + "]"); StringBuilder sb = new StringBuilder("Imported Keys Output:\n"); for (String t : tables) { ResultSet rs = dm.getImportedKeys(null, null, t); while (rs.next()) { sb.append(rs.getString(3)).append(':').append(rs.getString(4)); sb.append(" <- "); sb.append(rs.getString(7)).append(':').append(rs.getString(8)); sb.append('\n'); } rs.close(); } connection.close(); System.out.println(sb.toString()); } catch (Exception se) { System.out.println(se.getMessage()); } } }