Example usage for java.sql DatabaseMetaData getConnection

List of usage examples for java.sql DatabaseMetaData getConnection

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData getConnection.

Prototype

Connection getConnection() throws SQLException;

Source Link

Document

Retrieves the connection that produced this metadata object.

Usage

From source file:org.xenei.bloomgraph.bloom.sql.MySQLCommands.java

/**
 * Create the page stats table./*  w w  w  .  j a  v  a2 s.c om*/
 * 
 * @param metadata
 *            the metadata for the database.
 * @throws SQLException
 *             on error
 */
private void createPageStatsTable(final DatabaseMetaData metadata) throws SQLException {
    ResultSet rs = null;
    Statement stmt = null;
    final Connection connection = metadata.getConnection();
    try {
        rs = metadata.getTables(connection.getCatalog(), connection.getSchema(), getPageStatsTableName(),
                new String[] { "TABLE" });
        if (!rs.next()) {
            stmt = connection.createStatement();
            stmt.execute(
                    "CREATE TABLE PageStats ( idx INT PRIMARY KEY, records INT, deletes INT, bytes INT ) ENGINE MyISAM");
        }
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(stmt);
    }
}