package dbj.jdbc; import java.sql.*; import java.io.*; import java.util.Properties; public class Schema { public static void printSchema (Connection con, String schema) throws SQLException { DatabaseMetaData db_meta = con.getMetaData (); String[] tbl_types = { "TABLE", "VIEW" }; ResultSet rset1 = db_meta.getTables (con.getCatalog (), schema, "%", tbl_types); while (rset1.next ()) { String tbl_name = rset1.getString ("TABLE_NAME"); System.out.println ("Tabelle: " + tbl_name); ResultSet rset2 = db_meta.getColumns (con.getCatalog (), schema, tbl_name, "%"); while (rset2.next ()) { String col_name = rset2.getString ("COLUMN_NAME"); String col_type = rset2.getString ("TYPE_NAME"); int col_size = rset2.getInt ("COLUMN_SIZE"); System.out.println ("\t" + col_name + " " + col_type + "(" + col_size + ")"); } System.out.println (); rset2.close (); } rset1.close (); } public static void main (String[] args) throws IOException { if (args.length != 1) { System.out.println ("usage: dbj.jdbc.Schema schema"); System.exit (1); } try { Connection con = Utils.getConnection (); printSchema (con, args[0]); } catch (SQLException exc) { exc.printStackTrace (); } } }