本文整理匯總了Java中java.sql.DatabaseMetaData.getImportedKeys方法的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseMetaData.getImportedKeys方法的具體用法?Java DatabaseMetaData.getImportedKeys怎麽用?Java DatabaseMetaData.getImportedKeys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.DatabaseMetaData
的用法示例。
在下文中一共展示了DatabaseMetaData.getImportedKeys方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testGetImportedKeys
import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
@Test public void testGetImportedKeys() throws SQLException {
DatabaseMetaData metadata = getDatabaseMetadata();
try (ResultSet rs = metadata.getImportedKeys(null, null, null)) {
ResultSetMetaData rsMeta = rs.getMetaData();
assertEquals(14, rsMeta.getColumnCount());
assertColumn(rsMeta, 1, "PKTABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 2, "PKTABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 3, "PKTABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 4, "PKCOLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 5, "FKTABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 6, "FKTABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 7, "FKTABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 8, "FKCOLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 9, "KEY_SEQ", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 10, "UPDATE_RULE", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 11, "DELETE_RULE", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 12, "FK_NAME", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 13, "PK_NAME", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 14, "DEFERABILITY", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
}
}
示例2: getTableImportedKeys
import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
public static List<Map<Integer, Object>> getTableImportedKeys(Connection conn, String tableSchema, String tableName) throws Exception {
List<Map<Integer, Object>> importedKeys = new ArrayList<Map<Integer, Object>>();
Map<Integer, Object> importedKey;
DatabaseMetaData databaseMetaData = conn.getMetaData();
if (tableSchema == null) {
tableSchema = getDefaultTableSchema(conn);
}
ResultSet rs = null;
try {
rs = databaseMetaData.getImportedKeys(null, tableSchema, tableName.toUpperCase());
while (rs.next()) {
importedKey = new HashMap<Integer, Object>();
int i = 1;
while (i <= 14) {
importedKey.put(i, rs.getObject(i));
i++;
}
importedKeys.add(importedKey);
}
return importedKeys;
} finally {
DbJdbcUtils.closeResultSet(rs);
}
}
示例3: getImportedKeys
import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
/**
* Call {@link DatabaseMetaData#getImportedKeys(String, String, String)},
* wrapping any internal runtime exception into an {@link SQLException}.
*/
public static ResultSet getImportedKeys(DatabaseMetaData dmd,
String catalog, String schema, String table) throws SQLException {
try {
return dmd.getImportedKeys(catalog, schema, table);
} catch (SQLException e) {
throw e;
} catch (Throwable t) {
throw new SQLException(t);
}
}
示例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();
}
}
示例5: testGetImportedKeysUsingInfoSchema
import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
/**
* Tests the implementation of Information Schema for foreign key.
*/
public void testGetImportedKeysUsingInfoSchema() throws Exception {
if (versionMeetsMinimum(5, 0, 7)) {
this.stmt.executeUpdate("DROP TABLE IF EXISTS child");
this.stmt.executeUpdate("DROP TABLE If EXISTS parent");
this.stmt.executeUpdate("CREATE TABLE parent(id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB");
this.stmt.executeUpdate(
"CREATE TABLE child(id INT, parent_id INT, " + "FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE SET NULL) ENGINE=INNODB");
Properties props = new Properties();
props.put("useInformationSchema", "true");
Connection conn1 = null;
try {
conn1 = getConnectionWithProps(props);
DatabaseMetaData metaData = conn1.getMetaData();
this.rs = metaData.getImportedKeys(null, null, "child");
this.rs.next();
assertEquals("parent", this.rs.getString("PKTABLE_NAME"));
assertEquals("id", this.rs.getString("PKCOLUMN_NAME"));
assertEquals("child", this.rs.getString("FKTABLE_NAME"));
assertEquals("parent_id", this.rs.getString("FKCOLUMN_NAME"));
} finally {
this.stmt.executeUpdate("DROP TABLE IF EXISTS child");
this.stmt.executeUpdate("DROP TABLE If EXISTS parent");
if (conn1 != null) {
conn1.close();
}
}
}
}
示例6: initForeignKeys
import java.sql.DatabaseMetaData; //導入方法依賴的package包/類
private void initForeignKeys(DatabaseMetaData meta) throws SQLException {
ResultSet rs = null;
try {
rs = meta.getImportedKeys(catalog, schema, name);
while ( rs.next() ) {
addForeignKey(rs);
}
}
finally {
if (rs != null) {
rs.close();
}
}
}
示例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))
{
}
}
}