當前位置: 首頁>>代碼示例>>Java>>正文


Java DatabaseMetaData.getCatalogs方法代碼示例

本文整理匯總了Java中java.sql.DatabaseMetaData.getCatalogs方法的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseMetaData.getCatalogs方法的具體用法?Java DatabaseMetaData.getCatalogs怎麽用?Java DatabaseMetaData.getCatalogs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.DatabaseMetaData的用法示例。


在下文中一共展示了DatabaseMetaData.getCatalogs方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBug21215151

import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
/**
 * Tests fix for BUG#21215151 - DATABASEMETADATA.GETCATALOGS() FAILS TO SORT RESULTS.
 * 
 * DatabaseMetaData.GetCatalogs() relies on the results of 'SHOW DATABASES' which deliver a sorted list of databases except for 'information_schema' which
 * is always returned in the first position.
 * This test creates set of databases around the relative position of 'information_schema' and checks the ordering of the final ResultSet.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug21215151() throws Exception {
    createDatabase("z_testBug21215151");
    createDatabase("j_testBug21215151");
    createDatabase("h_testBug21215151");
    createDatabase("i_testBug21215151");
    createDatabase("a_testBug21215151");

    DatabaseMetaData dbmd = this.conn.getMetaData();
    this.rs = dbmd.getCatalogs();

    System.out.println("Catalogs:");
    System.out.println("--------------------------------------------------");
    while (this.rs.next()) {
        System.out.println("\t" + this.rs.getString(1));
    }
    this.rs.beforeFirst();

    // check the relative position of each element in the result set compared to the previous element.
    String previousDb = "";
    while (this.rs.next()) {
        assertTrue("'" + this.rs.getString(1) + "' is lexicographically lower than the previous catalog. Check the system output to see the catalogs list.",
                previousDb.compareTo(this.rs.getString(1)) < 0);
        previousDb = this.rs.getString(1);
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:36,代碼來源:MetaDataRegressionTest.java

示例2: getDataBases

import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
/**
 * 獲取有幾個數據庫(名稱)
 * @param con
 * @return
 */
public  List<String> getDataBases(){
	List<String> dataBases = new ArrayList<String>();
	ResultSet rs = null;
	if(con != null){
		try {
			DatabaseMetaData dbMetaData = con.getMetaData();
			rs = dbMetaData.getCatalogs();
			while(rs.next()){
				dataBases.add(rs.getString(1));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			close(rs,null,null);
		}
	}
	return dataBases;
}
 
開發者ID:ranji1221,項目名稱:clemon,代碼行數:24,代碼來源:JdbcUtil.java

示例3: getAllSchemaTables

import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
public static Map<String, List<String>> getAllSchemaTables(Connection conn) throws Exception {
	Map<String, List<String>> map = new HashMap<String, List<String>>();
	DatabaseMetaData databaseMetaData = conn.getMetaData();
	ResultSet rsCatalog = databaseMetaData.getCatalogs();
	ResultSet rsTable = null;
	try {
		while (rsCatalog.next()) {
			String catalog = rsCatalog.getString(1);
			List<String> tables = new ArrayList<String>();
			String[] t = { "TABLE" };
			rsTable = databaseMetaData.getTables(catalog, null, "%", t);
			while (rsTable.next()) {
				tables.add(rsTable.getString(3));
			}
			map.put(catalog, tables);
		}
	} finally {
		DbJdbcUtils.closeResultSet(rsCatalog);
		DbJdbcUtils.closeResultSet(rsTable);
	}
	return map;
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:23,代碼來源:DbJdbcUtils.java

示例4: testTwo

import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
/**
 * Basic test of DatabaseMetaData functions that access system tables
 */
public void testTwo() throws Exception {

    Connection conn = newConnection();
    int        updateCount;

    try {
        TestUtil.testScript(conn, "testrun/hsqldb/TestSelf.txt");

        DatabaseMetaData dbmeta = conn.getMetaData();

        dbmeta.allProceduresAreCallable();
        dbmeta.getBestRowIdentifier(null, null, "T_1",
                                    DatabaseMetaData.bestRowTransaction,
                                    true);
        dbmeta.getCatalogs();
        dbmeta.getColumnPrivileges(null, "PUBLIC", "T_1", "%");
        dbmeta.getColumns("PUBLIC", "PUBLIC", "T_1", "%");
        dbmeta.getCrossReference(null, null, "T_1", null, null, "T_1");
        dbmeta.getExportedKeys(null, null, "T_1");
        dbmeta.getFunctionColumns(null, "%", "%", "%");
        dbmeta.getFunctions(null, "%", "%");
        dbmeta.getImportedKeys("PUBLIC", "PUBLIC", "T_1");
        dbmeta.getIndexInfo("PUBLIC", "PUBLIC", "T1", true, true);
        dbmeta.getPrimaryKeys("PUBLIC", "PUBLIC", "T_1");
        dbmeta.getProcedureColumns(null, null, "%", "%");
        dbmeta.getProcedures("PUBLIC", "%", "%");
        dbmeta.getSchemas(null, "#");
        dbmeta.getTablePrivileges(null, "%", "%");
        dbmeta.getUDTs(null, "%", "%", new int[]{ Types.DISTINCT });
    } catch (Exception e) {
        assertTrue("unable to prepare or execute DDL", false);
    } finally {
        conn.close();
    }
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:39,代碼來源:TestDatabaseMetaData.java

示例5: getAllSchemasFromDB

import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
public static String[] getAllSchemasFromDB(String dsName) {
	Connection conn = null;
	ResultSet rs = null;

	try {
		conn = DBPower.getConnection(dsName);

		DatabaseMetaData metaData = conn.getMetaData();

		String databaseProductName = DBUtil.getDatabaseProductName(conn);
		if (databaseProductName == DBUtil.MYSQL
				|| databaseProductName == DBUtil.SQLSERVER) {
			rs = metaData.getCatalogs();
		} else {
			rs = metaData.getSchemas();
		}

		List result = new LinkedList();
		while (rs.next()) {
			String name = rs.getString(1);
			result.add(name);
		}

		String[] names = new String[result.size()];
		Iterator itr = result.iterator();
		for (int i = 0; i < names.length; i++) {
			names[i] = (String) itr.next();
		}
		return names;
	} catch (SQLException e) {
		log.error( "", e );
		throw new DBLevelException(e);
	} finally {
		DBUtil.close(rs);
		DBUtil.close(conn);
	}
}
 
開發者ID:yswang0927,項目名稱:ralasafe,代碼行數:38,代碼來源:DBView.java

示例6: testGetCatalogs

import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
@Test public void testGetCatalogs() throws SQLException {
  DatabaseMetaData metadata = getDatabaseMetadata();
  try (ResultSet rs = metadata.getCatalogs()) {
    ResultSetMetaData rsMeta = rs.getMetaData();

    assertEquals(1, rsMeta.getColumnCount());
    assertColumn(rsMeta, 1, "TABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
  }
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:10,代碼來源:MetaResultSetTest.java

示例7: runOtherMetaDataTests

import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
private void runOtherMetaDataTests() throws SQLException
{
	DatabaseMetaData metadata = connection.getMetaData();
	try (ResultSet rs = metadata.getCatalogs())
	{
	}
	try (ResultSet rs = metadata.getAttributes("", "", null, null))
	{
	}
	try (ResultSet rs = metadata.getClientInfoProperties())
	{
	}
	try (ResultSet rs = metadata.getFunctionColumns("", "", null, null))
	{
	}
	try (ResultSet rs = metadata.getFunctions("", "", null))
	{
	}
	try (ResultSet rs = metadata.getProcedureColumns("", "", null, null))
	{
	}
	try (ResultSet rs = metadata.getProcedures("", "", null))
	{
	}
	try (ResultSet rs = metadata.getSchemas())
	{
	}
	try (ResultSet rs = metadata.getSchemas("", null))
	{
	}
	try (ResultSet rs = metadata.getSuperTypes("", "", null))
	{
	}
	try (ResultSet rs = metadata.getTableTypes())
	{
	}
	try (ResultSet rs = metadata.getTypeInfo())
	{
	}
	try (ResultSet rs = metadata.getUDTs(null, null, null, null))
	{
	}
	for (String table : TABLES)
	{
		try (ResultSet rs = metadata.getExportedKeys("", "", table))
		{
		}
		try (ResultSet rs = metadata.getImportedKeys("", "", table))
		{
		}
		try (ResultSet rs = metadata.getBestRowIdentifier("", "", table, DatabaseMetaData.bestRowTransaction,
				false))
		{
		}
		try (ResultSet rs = metadata.getColumnPrivileges("", "", table, null))
		{
		}
		try (ResultSet rs = metadata.getPrimaryKeys("", "", table))
		{
		}
		try (ResultSet rs = metadata.getPseudoColumns("", "", table, null))
		{
		}
		try (ResultSet rs = metadata.getSuperTables("", "", table))
		{
		}
		try (ResultSet rs = metadata.getTablePrivileges("", "", table))
		{
		}
		try (ResultSet rs = metadata.getVersionColumns("", "", table))
		{
		}
	}
}
 
開發者ID:olavloite,項目名稱:spanner-jdbc,代碼行數:75,代碼來源:MetaDataTester.java


注:本文中的java.sql.DatabaseMetaData.getCatalogs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。