Search in sources :

Example 56 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project dubbo by alibaba.

the class DatabaseStatusChecker method check.

public Status check() {
    boolean ok;
    try {
        Connection connection = dataSource.getConnection();
        try {
            DatabaseMetaData metaData = connection.getMetaData();
            ResultSet resultSet = metaData.getTypeInfo();
            try {
                ok = resultSet.next();
            } finally {
                resultSet.close();
            }
            if (message == null) {
                message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")";
            }
            if (version == 0) {
                version = metaData.getDatabaseMajorVersion();
            }
        } finally {
            connection.close();
        }
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        ok = false;
    }
    return new Status(!ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message);
}
Also used : Status(com.alibaba.dubbo.common.status.Status) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 57 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project dubbo by alibaba.

the class DatabaseStatusChecker method check.

public Status check() {
    boolean ok;
    try {
        Connection connection = dataSource.getConnection();
        try {
            DatabaseMetaData metaData = connection.getMetaData();
            ResultSet resultSet = metaData.getTypeInfo();
            try {
                ok = resultSet.next();
            } finally {
                resultSet.close();
            }
            if (message == null) {
                message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")";
            }
            if (version == 0) {
                version = metaData.getDatabaseMajorVersion();
            }
        } finally {
            connection.close();
        }
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        ok = false;
    }
    return new Status(!ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message);
}
Also used : Status(com.alibaba.dubbo.common.status.Status) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 58 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project druid by alibaba.

the class ConnectionProxyImpl method getMetaData.

@Override
public DatabaseMetaData getMetaData() throws SQLException {
    FilterChainImpl chain = createChain();
    DatabaseMetaData value = chain.connection_getMetaData(this);
    recycleFilterChain(chain);
    return value;
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 59 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project GNS by MobilityFirst.

the class SimpleKeyStore method tableExists.

private boolean tableExists(String name) {
    try {
        DatabaseMetaData dbm = conn.getMetaData();
        ResultSet resultSet = dbm.getTables(null, null, name, null);
        return resultSet.next();
    } catch (SQLException e) {
        DerbyControl.printSQLException(e);
        return false;
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 60 with DatabaseMetaData

use of java.sql.DatabaseMetaData in project GNS by MobilityFirst.

the class SimpleKeyStore method showAllTables.

private void showAllTables() {
    try {
        DatabaseMetaData meta = conn.getMetaData();
        ResultSet resultSet = meta.getColumns(null, null, null, null);
        while (resultSet.next()) {
            if (!resultSet.getString("TABLE_NAME").startsWith("SYS")) {
                GNSClientConfig.getLogger().log(Level.FINE, "TABLE: {0}", resultSet.getString("TABLE_NAME"));
            }
        }
    } catch (SQLException e) {
        DerbyControl.printSQLException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData)

Aggregations

DatabaseMetaData (java.sql.DatabaseMetaData)360 ResultSet (java.sql.ResultSet)215 Connection (java.sql.Connection)169 SQLException (java.sql.SQLException)154 Test (org.junit.Test)87 Statement (java.sql.Statement)49 ResultSetMetaData (java.sql.ResultSetMetaData)42 ArrayList (java.util.ArrayList)40 PreparedStatement (java.sql.PreparedStatement)38 IOException (java.io.IOException)26 Properties (java.util.Properties)25 HashSet (java.util.HashSet)16 PhoenixDatabaseMetaData (org.apache.phoenix.jdbc.PhoenixDatabaseMetaData)16 HashMap (java.util.HashMap)15 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)15 PrintWriter (java.io.PrintWriter)10 Savepoint (java.sql.Savepoint)10 List (java.util.List)10 Map (java.util.Map)9 DataSource (javax.sql.DataSource)9