List of usage examples for java.sql DatabaseMetaData getTables
ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String types[])
throws SQLException;
From source file:edu.cornell.mannlib.vivo.utilities.rdbmigration.RdbMigrator.java
private boolean isAlreadyMigrated() throws SQLException { try (Connection conn = getSqlConnection()) { DatabaseMetaData md = conn.getMetaData(); try (ResultSet rs = md.getTables(null, null, TABLE_MIGRATED, null);) { if (rs.next()) { alreadyMigrated = true;//from w w w. j ava2s . c o m announceMigrationDate(conn); return true; } else { return false; } } } }
From source file:com.redhat.victims.database.VictimsSQL.java
protected boolean isSetUp(Connection connection) throws SQLException { boolean result = false; DatabaseMetaData dbm = connection.getMetaData(); ResultSet rs = dbm.getTables(null, null, "RECORDS", null); result = rs.next();//from w w w . jav a 2 s. c om rs.close(); return result; }
From source file:co.marcin.novaguilds.impl.storage.AbstractDatabaseStorage.java
/** * Checks if tables exist in the database * * @return boolean//from w ww.j a va2 s . com */ protected boolean checkTables() throws SQLException { DatabaseMetaData md = getConnection().getMetaData(); ResultSet rs = md.getTables(null, null, Config.MYSQL_PREFIX.getString() + "%", null); return rs.next(); }
From source file:com.abixen.platform.service.businessintelligence.multivisualisation.application.service.database.AbstractDatabaseService.java
protected ResultSet getTablesAsResultSet(Connection connection) throws SQLException { DatabaseMetaData md = connection.getMetaData(); return md.getTables(null, null, "%", null); }
From source file:net.riezebos.thoth.configuration.persistence.dbs.DDLExecuter.java
public boolean tableExists(String tableName, String schemaName) throws SQLException { DatabaseMetaData md = getConnection().getMetaData(); tableName = databaseIdiom.getTableName(tableName); try (ResultSet rs = md.getTables(null, null, tableName, new String[] { "TABLE" })) { return rs.next(); }/*from w w w . j a va2 s .c om*/ }
From source file:org.talend.core.model.metadata.builder.database.DqRepositoryViewService.java
/** * ADD gdbu 2011-7-25 bug : 23220/* w w w . j av a 2s . co m*/ * * This method is used to connect to database to check if this catalog has Children. * * @param dataProvider * @param catalog * @param childrenPattern * @param String[] childrenTypes * @return boolean * @throws Exception */ public static boolean isCatalogHasChildren(Connection dataProvider, Catalog catalog, String childrenPattern, String[] childrenTypes) throws Exception { TypedReturnCode<java.sql.Connection> rcConn = MetadataConnectionUtils .createConnection((DatabaseConnection) dataProvider); java.sql.Connection connection = rcConn.getObject(); DatabaseMetaData dbJDBCMetadata = null; ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance(); if (dataProvider instanceof DatabaseConnection) { dbJDBCMetadata = extractMeta.getDatabaseMetaData(connection, (DatabaseConnection) dataProvider, false); } else { TaggedValue taggedValue = TaggedValueHelper.getTaggedValue(TaggedValueHelper.DBTYPE, dataProvider.getTaggedValue()); dbJDBCMetadata = extractMeta.getDatabaseMetaData(connection, taggedValue == null ? "default" : taggedValue.getValue());//$NON-NLS-1$ } Package catalogOrSchema = PackageHelper.getCatalogOrSchema(catalog); ResultSet tables = dbJDBCMetadata.getTables(catalogOrSchema.getName(), null, childrenPattern, childrenTypes); // MOD msjian TDQ-1806: fixed "Too many connections" try { if (tables.next()) { return true; } else { return false; } } finally { if (connection != null) { ConnectionUtils.closeConnection(connection); } } }
From source file:jp.co.tis.gsp.tools.db.EntityDependencyParser.java
private List<String> getAllTableNames(DatabaseMetaData metaData, String normalizedSchemaName) throws SQLException { List<String> allNames = new ArrayList<String>(); String[] types = { "TABLE" }; ResultSet rs = null;//from w w w. j a va 2s. co m try { rs = metaData.getTables(null, normalizedSchemaName, "%", types); while (rs.next()) { allNames.add(rs.getString("TABLE_NAME")); } } finally { if (rs != null) { rs.close(); } } return allNames; }
From source file:edu.umass.cs.gnsclient.client.util.keystorage.SimpleKeyStore.java
private boolean tableExists(String name) { try {// ww w . j av a2 s . c om DatabaseMetaData dbm = conn.getMetaData(); ResultSet resultSet = dbm.getTables(null, null, name, null); return resultSet.next(); } catch (SQLException e) { DerbyControl.printSQLException(e); return false; } }
From source file:com.adito.jdbc.DBDumper.java
/** * Dump table creation SQL. It is up to the caller to close the stream and connections when * finished with./*from w w w. j a v a2 s . co m*/ * * @param writer write SQL to this writer. * @param conx connection to get data from * @param quoteChar character to use to quote strings * @param tables array of table names or <code>null</code> to dump all in * database * @throws Exception on any error */ public void dumpData(PrintWriter writer, JDBCConnectionImpl conx, char quoteChar, String[] tables) throws Exception { Connection jdbcConnection = conx.getConnection(); DatabaseMetaData dbMetaData = jdbcConnection.getMetaData(); if (tables == null) { ResultSet rs = dbMetaData.getTables(null, null, null, null); try { while (rs.next()) { String tableName = rs.getString("TABLE_NAME"); String tableType = rs.getString("TABLE_TYPE"); if (tableType.equalsIgnoreCase("TABLE")) { dumpData(writer, conx, quoteChar, new String[] { tableName }); } } } finally { rs.close(); } } else { for (int i = 0; i < tables.length; i++) { String tableName = tables[i]; log.info("Dumping data for table " + tableName); // Data PreparedStatement stmt = jdbcConnection.prepareStatement("SELECT * FROM " + tableName); try { ResultSet rs2 = stmt.executeQuery(); try { while (rs2.next()) { dumpRow(writer, rs2); } } finally { rs2.close(); } } finally { stmt.close(); } writer.println(); } } }
From source file:net.hydromatic.optiq.impl.jdbc.JdbcSchema.java
private ImmutableMap<String, JdbcTable> computeTables() { Connection connection = null; ResultSet resultSet = null;//from w w w . j av a 2 s. c o m try { connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); resultSet = metaData.getTables(catalog, schema, null, null); final ImmutableMap.Builder<String, JdbcTable> builder = ImmutableMap.builder(); while (resultSet.next()) { final String tableName = resultSet.getString(3); final String catalogName = resultSet.getString(1); final String schemaName = resultSet.getString(2); final String tableTypeName = resultSet.getString(4); final TableType tableType = Util.enumVal(TableType.class, tableTypeName); final JdbcTable table = new JdbcTable(this, catalogName, schemaName, tableName, tableType); builder.put(tableName, table); } return builder.build(); } catch (SQLException e) { throw new RuntimeException("Exception while reading tables", e); } finally { close(connection, null, resultSet); } }