当前位置: 首页>>代码示例>>Java>>正文


Java DatabaseMetaData.getTables方法代码示例

本文整理汇总了Java中java.sql.DatabaseMetaData.getTables方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseMetaData.getTables方法的具体用法?Java DatabaseMetaData.getTables怎么用?Java DatabaseMetaData.getTables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.DatabaseMetaData的用法示例。


在下文中一共展示了DatabaseMetaData.getTables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: FileExists

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
@Override
public boolean FileExists(String fName) {
    CheckConnection();

    fName = validateFname(fName);

    try (Statement statement = connection.createStatement()) {
        statement.setQueryTimeout(10);

        DatabaseMetaData md = connection.getMetaData();
        try (ResultSet rs = md.getTables(null, null, "" + dbprefix + fName, null)) {
            return rs.next();
        }
    } catch (SQLException ex) {
        com.gmt2001.Console.err.printStackTrace(ex);
    }

    return false;
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:20,代码来源:MySQLStore.java

示例2: createTable

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
 * Creates the target table if it does not already exist in the database
 * @param frame     the DataFrame to create a table for
 * @param options   the sink options
 * @throws DataFrameException   if this operation fails
 */
private void createTable(DataFrame<R,C> frame, DbSinkOptions<R,C> options) {
    final Connection conn = options.getConnection();
    final String tableName = options.getTableName();
    try (Statement stmt = conn.createStatement()) {
        final DatabaseMetaData metaData = conn.getMetaData();
        final ResultSet tables = metaData.getTables(null, null, tableName, null);
        if (tables.next()) {
            System.out.println("The table named " + tableName + " already exists");
        } else {
            final String ddl = getCreateTableSql(frame, options);
            System.out.println("Executing DDL:\n " + ddl);
            stmt.executeUpdate(ddl);
        }
    } catch (Exception ex) {
        throw new DataFrameException("Failed to create table named " + tableName + " in database", ex);
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:24,代码来源:DbSink.java

示例3: getTables

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
public  List<String> getTables(String dataBaseName){
	List<String> tables = new ArrayList<String>();
	ResultSet rs = null;
	if(con != null){
		try {
			DatabaseMetaData dbMetaData = con.getMetaData();
			rs = dbMetaData.getTables(dataBaseName, null, null, new String[]{"TABLE","VIEW"});
			while(rs.next()){
				tables.add(rs.getString("TABLE_NAME"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			close(rs,null,null);
		}
	}
	return tables;
}
 
开发者ID:ranji1221,项目名称:clemon,代码行数:19,代码来源:JdbcUtil.java

示例4: testQuotedGunk

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
public void testQuotedGunk() throws Exception {
    createTable("testQuotedGunk", "(field1 int)");

    String quotedCatalog = "`" + this.conn.getCatalog() + "`";
    String unquotedCatalog = this.conn.getCatalog();

    DatabaseMetaData dbmd = this.conn.getMetaData();
    this.rs = dbmd.getTables(quotedCatalog, null, "testQuotedGunk", new String[] { "TABLE" });
    assertTrue(this.rs.next());
    this.rs = dbmd.getTables(unquotedCatalog, null, "testQuotedGunk", new String[] { "TABLE" });
    assertTrue(this.rs.next());
    this.rs = dbmd.getColumns(quotedCatalog, null, "testQuotedGunk", "field1");
    assertTrue(this.rs.next());
    this.rs = dbmd.getColumns(unquotedCatalog, null, "testQuotedGunk", "field1");
    assertTrue(this.rs.next());

}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:18,代码来源:MetaDataRegressionTest.java

示例5: tableExists

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
private boolean tableExists(Handle h, String tableName) {
    try {
        String tableToCheck = tableName;
        boolean caseSensitive = this.databaseKind == DatabaseKind.PostgreSQL;
        if (!caseSensitive) {
            tableToCheck = tableName.toUpperCase(Locale.ROOT);
        }
        DatabaseMetaData metaData = h.getConnection().getMetaData();

        try (ResultSet rs = metaData.getTables(null, null, tableToCheck, null)) {
            while (rs.next()) {
                String foundTable = rs.getString("TABLE_NAME");
                if (tableToCheck.equalsIgnoreCase(foundTable)) {
                    return true;
                }
            }
        }
        return false;
    } catch (SQLException ex) {
        throw IconDataAccessException.launderThrowable("Cannot check if the table " + tableName + " already exists", ex);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:23,代码来源:SqlIconFileStore.java

示例6: tableExists

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
private boolean tableExists(Handle h, String tableName) {
    try {
        String tableToCheck = tableName;
        boolean caseSensitive = this.databaseKind == DatabaseKind.PostgreSQL;
        if (!caseSensitive) {
            tableToCheck = tableName.toUpperCase(Locale.ROOT);
        }
        DatabaseMetaData metaData = h.getConnection().getMetaData();

        try (ResultSet rs = metaData.getTables(null, null, tableToCheck, null)) {
            while (rs.next()) {
                String foundTable = rs.getString("TABLE_NAME");
                if (tableToCheck.equalsIgnoreCase(foundTable)) {
                    return true;
                }
            }
        }
        return false;
    } catch (SQLException ex) {
        throw ExtensionDataAccessException.launderThrowable("Cannot check if the table " + tableName + " already exists", ex);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:23,代码来源:SqlExtensionFileStore.java

示例7: createTaskRunningTableIfNeeded

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
private void createTaskRunningTableIfNeeded(final Connection conn) throws SQLException {
    DatabaseMetaData dbMetaData = conn.getMetaData();
    try (ResultSet resultSet = dbMetaData.getTables(null, null, TABLE_TASK_RUNNING_STATISTICS, new String[]{"TABLE"})) {
        if (!resultSet.next()) {
            createTaskRunningTable(conn);
        }
    }
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:9,代码来源:StatisticRdbRepository.java

示例8: existsTable

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
 * Check if the person table already exists.
 */
private boolean existsTable(Connection conn) throws SQLException {
    DatabaseMetaData meta = conn.getMetaData();
    ResultSet rs = meta.getTables(null, null, "T_PERSONS", null);
    while (rs.next()) {
        String name = rs.getString("TABLE_NAME");
        if (name.equals("T_PERSONS")) {
            return true;
        }
    }
    return false;
}
 
开发者ID:qianyilun,项目名称:Queue-Manager-Cloud-Dispatcher,代码行数:15,代码来源:PersonDAO.java

示例9: getTables

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
 * Call {@link DatabaseMetaData#getTables(String, String, String,
 * String[])}, wrapping any internal runtime exception into an
 * {@link SQLException}.
 */
public static ResultSet getTables(DatabaseMetaData dmd,
        String catalog, String schemaPattern, String tableNamePattern,
        String[] types) throws SQLException {
    try {
        return dmd.getTables(catalog, schemaPattern, tableNamePattern,
                types);
    } catch (SQLException e) {
        throw e;
    } catch (Throwable t) {
        throw new SQLException(t);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:MetadataUtilities.java

示例10: existsTable

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
 * Check if the table already exists.
 */
private boolean existsTable(Connection conn) throws SQLException {
    DatabaseMetaData meta = conn.getMetaData();
    ResultSet rs = meta.getTables(null, null, "ROOT", null);
    while (rs.next()) {
        String name = rs.getString("TABLE_NAME");
        if (name.equals("ROOT")) {
            return true;
        }
    }
    return false;
}
 
开发者ID:qianyilun,项目名称:Queue-Manager-Cloud-Dispatcher,代码行数:15,代码来源:TemplateDAO.java

示例11: findTableInfos

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
public List<TableInfo> findTableInfos(String dbInfoId) throws Exception {
	List<TableInfo> tablesList = new ArrayList<TableInfo>();
	DataSource ds = this.getDataSourceByDbInfoId(dbInfoId);
	Connection conn = null;
	ResultSet rs = null;
	try {
		conn = DataSourceUtils.getConnection(ds);
		DatabaseMetaData metaData = conn.getMetaData();
		String url = metaData.getURL();
		String schema = null;
		if (url.toLowerCase().contains("oracle")) {
			String value = Configure.getString("bdf2.default.schema");
			if (StringUtils.hasText(value)) {
				schema = value;
			} else {
				schema = metaData.getUserName();
			}
		}
		rs = metaData.getTables(null, schema, "%", new String[] { "TABLE" });
		TableInfo tableInfo = null;
		while (rs.next()) {
			tableInfo = new TableInfo();
			tableInfo.setTableName(rs.getString("TABLE_NAME"));
			tableInfo.setDbInfoId(dbInfoId);
			tablesList.add(tableInfo);
		}
		return tablesList;
	} finally {
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeConnection(conn);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:33,代码来源:DbCommonServiceImpl.java

示例12: testGetTablesZeroRowsByTableSchemaOrNameWorks

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/** (Failed before (because table schema and name tests are pushed down).) */
@Test
public void testGetTablesZeroRowsByTableSchemaOrNameWorks() throws Exception {
  DatabaseMetaData dbMetadata = connection.getMetaData();

  ResultSet results = dbMetadata.getTables( "NoSuchCatalog", "NoSuchSchema",
                                            "NoSuchTable", new String[0] );

  // Result set should still have columns even though there are no rows:
  ResultSetMetaData metadata = results.getMetaData();
  assertThat( "ResultSetMetaData.getColumnCount() should have been > 0",
              metadata.getColumnCount(), not( equalTo( 0 ) ) );
  assertThat( "Unexpected non-empty results.  Test rot?",
              false, equalTo( results.next() ) );
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:16,代码来源:Drill2288GetColumnsMetadataWhenNoRowsTest.java

示例13: fetchTables

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
static Set<String> fetchTables(final DatabaseMetaData meta, final String catalog,
    final String schemaPattern, final String tableNamePattern) throws SQLException {
    Set<String> tablesInSchema = new HashSet<>();
    ResultSet rs = meta.getTables(catalog, schemaPattern, tableNamePattern, new String[] { "TABLE" });
    while (rs.next()) {
        tablesInSchema.add(rs.getString(3).toUpperCase());
    }
    return tablesInSchema;
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:10,代码来源:DatabaseMetaDataHelper.java

示例14: putTableMeta

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
 *
 * @param repo
 * @param conn
 * @param dbmd
 * @param objectInserter
 * @param dbMetaTree
 * @param clmnTree
 * @return
 */
public static TreeFormatter putTableMeta(Repository repo, Connection conn,
        DatabaseMetaData dbmd, ObjectInserter objectInserter, TreeFormatter dbMetaTree, Boolean clmnTree) {

    String[] types = {"TABLE"};

    try {

        ResultSet tables = dbmd.getTables(null, null, null, types);
        RevWalk walkTbl = new RevWalk(repo);

        while (tables.next()) {
            System.out.println("***************************************");
            String tableName = tables.getString(Consts.TABLE_NAME);

            TreeFormatter tblMetaTree = new TreeFormatter();

            // Build tree for table attributs
            buildMetaTree(tables, Consts.TABLE_META_ATTRIBUTES, objectInserter, tblMetaTree);

            ResultSet columns = dbmd.getColumns(null, null, tableName, null);
            if (clmnTree) {
                addColumnsAsTrees(columns, objectInserter, tblMetaTree, walkTbl, dbMetaTree);
            } else {
                addColumnsAsObjects(columns, objectInserter, tblMetaTree, walkTbl, dbMetaTree);
            }

            TreeFormatter tblDataTree = new TreeFormatter();
            ObjectId tblDataTreeId = objectInserter.insert(tblDataTree);
            objectInserter.flush();

            dbMetaTree.append(Consts.TABLE_DATA, walkTbl.parseTree(tblDataTreeId));
        }
    } catch (SQLException | IOException ex) {
        System.out.println(ex.getMessage());
    }
    return dbMetaTree;
}
 
开发者ID:alexmy21,项目名称:gmds,代码行数:48,代码来源:Utils.java

示例15: createJobStatusTraceTableAndIndexIfNeeded

import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
private void createJobStatusTraceTableAndIndexIfNeeded(final Connection conn) throws SQLException {
    DatabaseMetaData dbMetaData = conn.getMetaData();
    try (ResultSet resultSet = dbMetaData.getTables(null, null, TABLE_JOB_STATUS_TRACE_LOG, new String[]{"TABLE"})) {
        if (!resultSet.next()) {
            createJobStatusTraceTable(conn);
        }
    }
    createTaskIdIndexIfNeeded(conn, TABLE_JOB_STATUS_TRACE_LOG, TASK_ID_STATE_INDEX);
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:10,代码来源:JobEventRdbStorage.java


注:本文中的java.sql.DatabaseMetaData.getTables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。