Skip to content

Instantly share code, notes, and snippets.

@sualeh
Created March 1, 2018 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sualeh/97ae60a0d8f7a0a8d47bc1f42669421d to your computer and use it in GitHub Desktop.
Save sualeh/97ae60a0d8f7a0a8d47bc1f42669421d to your computer and use it in GitHub Desktop.
SchemaCrawler Issue #167
import static us.fatehi.commandlineparser.CommandLineUtility.applyApplicationLogLevel;
import static us.fatehi.commandlineparser.CommandLineUtility.logSystemProperties;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;
import java.util.logging.Level;
import javax.sql.DataSource;
import schemacrawler.schema.Catalog;
import schemacrawler.schema.Column;
import schemacrawler.schema.JavaSqlType;
import schemacrawler.schema.Schema;
import schemacrawler.schema.Table;
import schemacrawler.schemacrawler.DatabaseConnectionOptions;
import schemacrawler.schemacrawler.ExcludeAll;
import schemacrawler.schemacrawler.RegularExpressionInclusionRule;
import schemacrawler.schemacrawler.SchemaCrawlerException;
import schemacrawler.schemacrawler.SchemaCrawlerOptions;
import schemacrawler.tools.options.InfoLevel;
import schemacrawler.utility.SchemaCrawlerUtility;
public final class Issue167
{
public static void main(final String[] args)
throws Exception
{
// Turn application logging on by applying the correct log level
applyApplicationLogLevel(Level.OFF);
// Log system properties and classpath
logSystemProperties();
final Connection connection = getConnection();
final SchemaCrawlerOptions sco = new SchemaCrawlerOptions();
sco.setSchemaInfoLevel(InfoLevel.standard.buildSchemaInfoLevel());
sco.setRoutineInclusionRule(new ExcludeAll());
sco
.setSchemaInclusionRule(new RegularExpressionInclusionRule("SVIL"));
sco.setTableNamePattern("XGPI_DDL_ORACLE%");
final Catalog catalog = SchemaCrawlerUtility.getCatalog(connection, sco);
final Schema schema = catalog.getSchemas().iterator().next();
if (catalog != null)
{
final Collection<Table> tablesList = catalog.getTables(schema);
final Iterator<Table> i = tablesList.iterator();
Table tbl;
while (i.hasNext())
{
tbl = i.next();
System.out.println(tbl);
for (final Column col: tbl.getColumns())
{
final JavaSqlType sqlType = col.getColumnDataType().getJavaSqlType();
System.out
.println("o--> " + col.getName() + " -data-type- " + sqlType);
}
}
}
}
private static Connection getConnection()
throws SchemaCrawlerException, SQLException
{
final DataSource dataSource = new DatabaseConnectionOptions("jdbc:oracle:thin:@srvsvil:1521:orcl");
return dataSource.getConnection("username", "password");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment