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


Java Connection.getMetaData方法代码示例

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


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

示例1: testGetProceduresUsingInfoSchema

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests the implementation of Information Schema for description
 * of stored procedures available in a catalog.
 */
public void testGetProceduresUsingInfoSchema() throws Exception {
    if (versionMeetsMinimum(5, 0, 7)) {
        createProcedure("sp1", "()\n BEGIN\nSELECT 1;end\n");
        Properties props = new Properties();
        props.put("useInformationSchema", "true");
        Connection conn1 = null;
        try {
            conn1 = getConnectionWithProps(props);
            DatabaseMetaData metaData = conn1.getMetaData();
            this.rs = metaData.getProcedures(null, null, "sp1");
            this.rs.next();
            assertEquals("sp1", this.rs.getString("PROCEDURE_NAME"));
            assertEquals("1", this.rs.getString("PROCEDURE_TYPE"));
        } finally {
            if (conn1 != null) {
                conn1.close();
            }
        }
    }
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:25,代码来源:MetadataTest.java

示例2: checkGetFunctionsForBug69298

import java.sql.Connection; //导入方法依赖的package包/类
private void checkGetFunctionsForBug69298(String stepDescription, Connection testConn) throws Exception {
    DatabaseMetaData testDbMetaData = testConn.getMetaData();
    ResultSet functionsMD = testDbMetaData.getFunctions(null, null, "testBug69298_%");
    String sd = stepDescription + " getFunctions() ";

    assertTrue(sd + "one row expected.", functionsMD.next());

    // function: testBug69298_func
    assertEquals(sd + "-> FUNCTION_CAT", testConn.getCatalog(), functionsMD.getString("FUNCTION_CAT"));
    assertEquals(sd + "-> FUNCTION_SCHEM", null, functionsMD.getString("FUNCTION_SCHEM"));
    assertEquals(sd + "-> FUNCTION_NAME", "testBug69298_func", functionsMD.getString("FUNCTION_NAME"));
    assertEquals(sd + "-> REMARKS", "testBug69298_func comment", functionsMD.getString("REMARKS"));
    assertEquals(sd + "-> FUNCTION_TYPE", DatabaseMetaData.functionNoTable, functionsMD.getShort("FUNCTION_TYPE"));
    assertEquals(sd + "-> SPECIFIC_NAME", "testBug69298_func", functionsMD.getString("SPECIFIC_NAME"));

    assertFalse(stepDescription + "no more rows expected.", functionsMD.next());
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:18,代码来源:MetaDataRegressionTest.java

示例3: columnInIndex

import java.sql.Connection; //导入方法依赖的package包/类
public boolean columnInIndex(Connection conn, String schemaName, String tableName, String colname, String indexName)
        throws Exception {
    DatabaseMetaData md = conn.getMetaData();
    ResultSet rs = md.getIndexInfo(null, schemaName, tableName, false, false);

    while ( rs.next() ) {
        String ixName = rs.getString(6);
        if ( ixName != null && ixName.equals(indexName)) {
            String ixColName = rs.getString(9);
            if ( ixColName.equals(colname) ) {
                return true;
            }
        }
    }

    return false;
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:DefaultDBProvider.java

示例4: testGetPrimaryKeysUsingInfoShcema

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Tests the implementation of Information Schema for primary keys.
 */
public void testGetPrimaryKeysUsingInfoShcema() throws Exception {
    if (versionMeetsMinimum(5, 0, 7)) {
        createTable("t1", "(c1 int(1) primary key)");
        Properties props = new Properties();
        props.put("useInformationSchema", "true");
        Connection conn1 = null;
        try {
            conn1 = getConnectionWithProps(props);
            DatabaseMetaData metaData = conn1.getMetaData();
            this.rs = metaData.getPrimaryKeys(null, null, "t1");
            this.rs.next();
            assertEquals("t1", this.rs.getString("TABLE_NAME"));
            assertEquals("c1", this.rs.getString("COLUMN_NAME"));
        } finally {
            if (conn1 != null) {
                conn1.close();
            }
        }
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:24,代码来源:MetadataTest.java

示例5: showDataTypes

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Retrieves a description of all the data types supported by the data
 * source.
 * 
 * @param conn
 *            The connection used to list the data types.
 * @throws SQLException
 *             if error happens while querying the data source.
 */
private static void showDataTypes(Connection conn) throws SQLException {
	assert (conn != null);

	DatabaseMetaData meta = conn.getMetaData();

	ResultSet result = null;
	try {
		result = meta.getTypeInfo();
		printResultSet(result);
	} finally {
		if (result != null) {
			result.close();
		}
	}
}
 
开发者ID:kineticadb,项目名称:kinetica-client-jdbc,代码行数:25,代码来源:JDBCSample.java

示例6: checkDBProductName

import java.sql.Connection; //导入方法依赖的package包/类
public String checkDBProductName() throws Exception {
	Connection conn = null;
	String dbProductName = null;

	try {
		if (Log.doTrace())
			Log.traceEnter("TradeDirect:checkDBProductName");

		conn = getConn();
		DatabaseMetaData dbmd = conn.getMetaData();
		dbProductName = dbmd.getDatabaseProductName();
	} catch (SQLException e) {
		Log
				.error(
						e,
						"TradeDirect:checkDBProductName() -- Error checking the Daytrader Database Product Name");
	} finally {
		releaseConn(conn);
	}
	return dbProductName;
}
 
开发者ID:WASdev,项目名称:sample.daytrader3,代码行数:22,代码来源:TradeDirect.java

示例7: setUpConnection

import java.sql.Connection; //导入方法依赖的package包/类
@BeforeClass
public static void setUpConnection() throws Exception {
  // (Note: Can't use JdbcTest's connect(...) for this test class.)
  final Connection connection =
      new Driver().connect( "jdbc:drill:zk=local", JdbcAssert.getDefaultProperties() );
  final Statement stmt = connection.createStatement();
  final ResultSet result =
      stmt.executeQuery( "SELECT * FROM INFORMATION_SCHEMA.CATALOGS" );
  result.next();
  final DatabaseMetaData dbmd = connection.getMetaData();

  result.close();
  closedResultSet = result;
  stmt.close();
  closedStatement = stmt;
  connection.close();
  closedConnection = connection;
  closedDatabaseMetaData = dbmd;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:20,代码来源:Drill2489CallsAfterCloseThrowExceptionsTest.java

示例8: testBug31187

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

    Connection nullCatConn = getConnectionWithProps("nullCatalogMeansCurrent=false");
    DatabaseMetaData dbmd = nullCatConn.getMetaData();
    ResultSet dbTblCols = dbmd.getColumns(null, null, "testBug31187", "%");

    boolean found = false;

    while (dbTblCols.next()) {
        String catalog = dbTblCols.getString("TABLE_CAT");
        String table = dbTblCols.getString("TABLE_NAME");
        boolean useLowerCaseTableNames = dbmd.storesLowerCaseIdentifiers();

        if (catalog.equals(nullCatConn.getCatalog())
                && (((useLowerCaseTableNames && "testBug31187".equalsIgnoreCase(table)) || "testBug31187".equals(table)))) {
            found = true;
        }
    }

    assertTrue("Didn't find any columns for table named 'testBug31187' in database " + this.conn.getCatalog(), found);
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:23,代码来源:MetaDataRegressionTest.java

示例9: findTablePrimaryKeys

import java.sql.Connection; //导入方法依赖的package包/类
public List<String> findTablePrimaryKeys(String dataSourceName, String tableName) throws Exception {
	List<String> primaryKeys = new ArrayList<String>();
	Connection conn = null;
	ResultSet rs = null;
	try {
		conn = connectionHelper.getConnection(dataSourceName);
		DatabaseMetaData metaData = conn.getMetaData();
		rs = metaData.getPrimaryKeys(null, null, tableName.toUpperCase());
		while (rs.next()) {
			primaryKeys.add(rs.getString("COLUMN_NAME").toLowerCase());
		}
		return primaryKeys;
	} finally {
		if (conn != null) {
			conn.close();
		}
		if (rs != null) {
			rs.close();
		}
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:22,代码来源:ExcelModelManager.java

示例10: check

import java.sql.Connection; //导入方法依赖的package包/类
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);
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:31,代码来源:DatabaseStatusChecker.java

示例11: main

import java.sql.Connection; //导入方法依赖的package包/类
/**
    * @param args
    */
   public static void main(String[] args) throws Exception {

Connection connection = ConnectionLoader.getLocalConnection();
DatabaseMetaData databaseMetaData = connection.getMetaData();

JsonDatabaseMetaData jsonDatabaseMetaData = new JsonDatabaseMetaData(
	databaseMetaData);
String JsonString = jsonDatabaseMetaData.build();
System.out.println(JsonString);

   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:15,代码来源:JsonDatabaseMetaDataTest.java

示例12: execute

import java.sql.Connection; //导入方法依赖的package包/类
private void execute(Connection con, int schemaVersion) throws Exception
{
    final DatabaseMetaData dbmd = con.getMetaData();

    String schemaName = databaseMetaDataHelper.getSchema(con);

    schema = new Schema(schemaName, namePrefix, schemaVersion, true);
    String[] prefixFilters = namePrefixFilters(dbmd);
    
    for (String filter : prefixFilters)
    {
        extractSchema(dbmd, schemaName, filter);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:15,代码来源:ExportDb.java

示例13: main

import java.sql.Connection; //导入方法依赖的package包/类
public static void main(String[] args) {
    Connection conn = null;
    DatabaseMetaData dbmd;
    try {
        conn = DriverManager.getConnection(URL);
        dbmd = conn.getMetaData();
        if (dbmd != null) {
            ObjectJson builder = new ObjectJson();
            
            builder.addDoc("URL", dbmd.getURL());
            builder.addDoc("DatabaseProductVersion", dbmd.getDatabaseProductVersion());
            builder.addDoc("DriverName", dbmd.getDriverName());
         
            System.out.println(new Map2JsonString().convert(builder.getObjectAsMap()));
            System.out.println("\n");
            
            printTableMeta(conn, dbmd);

        } else {
            System.out.println("Metadata not supported");
        }
    } catch (SQLException ex1) {
        System.err.println(ex1);
    } finally {
        try {
            conn.close();
        } catch (SQLException ex2) {

        }
    }
}
 
开发者ID:alexmy21,项目名称:gmds,代码行数:32,代码来源:Main.java

示例14: tableExists

import java.sql.Connection; //导入方法依赖的package包/类
public static boolean tableExists(SQLConnection connection, String table) throws ClassNotFoundException, SQLException {
    checkAndOpen(connection);
    Connection c = connection.getConnection();
    DatabaseMetaData metaData = c.getMetaData();
    ResultSet rs = metaData.getTables(null, null, table, null);
    if (rs.next()) {
        return rs.getRow() == 1;
    }
    return false;
}
 
开发者ID:Warvale,项目名称:Locked,代码行数:11,代码来源:SQLUtil.java

示例15: checkMetaDataInfoForBug17248345

import java.sql.Connection; //导入方法依赖的package包/类
private void checkMetaDataInfoForBug17248345(Connection testConn) throws Exception {
    DatabaseMetaData testDbMetaData = testConn.getMetaData();
    ResultSet rsMD;
    boolean useInfoSchema = ((ConnectionProperties) testConn).getUseInformationSchema();
    boolean getProcRetFunc = ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions();
    String stepDescription = "Prop. useInfoSchema(" + (useInfoSchema ? 1 : 0) + ") + getProcRetFunc(" + (getProcRetFunc ? 1 : 0) + "):";
    String sd;

    // getProcedures() must return 2 records, even if getProceduresReturnsFunctions is false once this flag only
    // applies to JDBC4. When exists a procedure and a function with same name, function is returned first.
    sd = stepDescription + " getProcedures() ";
    rsMD = testDbMetaData.getProcedures(null, null, "testBug17248345");
    assertTrue(sd + "1st of 2 rows expected.", rsMD.next());
    assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
    assertTrue(sd + "2nd of 2 rows expected.", rsMD.next());
    assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
    assertFalse(sd + "no more rows expected.", rsMD.next());

    // getProcedureColumns() must return 3 records, even if getProceduresReturnsFunctions is false once this flag
    // only applies to JDBC4. When exists a procedure and a function with same name, function is returned first.
    sd = stepDescription + " getProcedureColumns() ";
    rsMD = testDbMetaData.getProcedureColumns(null, null, "testBug17248345", "%");
    assertTrue(sd + "1st of 3 rows expected.", rsMD.next());
    assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
    assertEquals(sd + " -> COLUMN_NAME", "", rsMD.getString("COLUMN_NAME"));
    assertTrue(sd + "2nd of 3 rows expected.", rsMD.next());
    assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
    assertEquals(sd + " -> COLUMN_NAME", "funccol", rsMD.getString("COLUMN_NAME"));
    assertTrue(sd + "3rd of 3 rows expected.", rsMD.next());
    assertEquals(sd + " -> PROCEDURE_NAME", "testBug17248345", rsMD.getString("PROCEDURE_NAME"));
    assertEquals(sd + " -> COLUMN_NAME", "proccol", rsMD.getString("COLUMN_NAME"));
    assertFalse(sd + "no more rows expected.", rsMD.next());
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:34,代码来源:MetaDataRegressionTest.java


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