Connection getMetaData - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Connection getMetaData method.

This code example shows how to use the following methods:sleep, close, createStatement, getMetaData
	    try 
	    { 
	      connection = ds.getConnection();
	      System.out.println("   Got connection");
 
	      connection.getMetaData();
 
	      int leased = ds.getTotalLeased();
 
	      System.out.println("      Leased (should be 1) = " + leased);
 
	      Statement stmt = connection.createStatement();
 
	      System.out.println("      Executing statement");
	      stmt.execute("select NOW()");
	      timedOut = false;
	    } 
	    catch (Throwable t)
	    { 
	      System.err.println("Exception: " + t.getMessage());

7
CodeRank
This code example shows how to use the following methods:getMetaData, setCatalog
        loadDbFromSqlFiles(dbPentahoDW, DB_PENTAHO_DW_SCRIPTS);
    } 
     
    private void loadDbFromSqlFiles(String dbToLoadName, String[] fileNames) throws SQLException, IOException {
        if (!"".equals(dbToLoadName)) {
            connection.setCatalog(dbToLoadName);
            ResultSet res = connection.getMetaData().getTables(null, null, null, new String[] { "TABLE" });
            if (res.next()) {
                logger.info("Database " + dbToLoadName + " already populated");
            } else { 
                InputStream[] inputStreams = MifosResourceUtil.getSQLFilesAsStreams(fileNames);
                SqlExecutor.executeMultipleFiles(inputStreams, connection);
            } 
        } 
    } 
 
    public String getDbName() {
        return dbName;
    } 
 
7
CodeRank
This code example shows how to use the following methods:close, createStatement, getMetaData
    } 
 
    public void tearDown() throws Exception { 
        try { 
            conn = Support_SQL.getConnection();
            meta = conn.getMetaData();
            statement = conn.createStatement();
            deleteTestTables(); 
        } catch (SQLException e) {
            System.out.println("Error in teardown: "+e.getMessage());
        } finally { 
            try { 
                conn.close();
            } catch (SQLException e) {
            } 
        } 
        super.tearDown(); 
    } 
 
    private void createTestTables() { 
7
CodeRank
This code example shows how to use the following methods:close, getMetaData, setAutoCommit
        Connection con = null;
        try 
        { 
            // make sure that we AUTO-COMMIT 
            con = session.connection();
            con.setAutoCommit(true);
            DatabaseMetaData meta = con.getMetaData();
            Dialect dialect = DialectFactory.buildDialect(cfg.getProperties(), meta.getDatabaseProductName(), meta
                    .getDatabaseMajorVersion());
            dialect = changeDialect(cfg, dialect);
            return dialect;
        } 
        finally 
        { 
            try 
            { 
                con.close();
            } 
            catch (Exception e)
            { 

6
CodeRank
This code example shows how to use the following methods:close, getMetaData, isClosed
		ResultSet rs = null;
 
		try { 
			connection = dataSource.getConnection();
 
			DatabaseMetaData meta = connection.getMetaData();
 
			rs = meta.getTables(null, null, tableName, null);
 
			if (rs.next()) {
				return true; 
			} 
		} finally { 
			closeResultSet(rs);
			closeConnection(connection);
		} 
 
		return false; 
	} 
 

6
CodeRank
This code example shows how to use the following methods:close, createStatement, getMetaData, prepareStatement
        // Load the HSQL Database Engine JDBC driver 
        Class.forName("org.hsqldb.jdbcDriver");
        connection = DriverManager.getConnection("jdbc:hsqldb:"+cacheFile.toURI().toString(), "sa", "");
        boolean mustCreateTable = false;
        if (clearCache) {
            Statement st = connection.createStatement();
            st.executeUpdate("DROP TABLE MARYCACHE IF EXISTS");
            st.close();
            mustCreateTable = true;
        } else { // don't clear -- check if table exists 
            DatabaseMetaData dbInfo = connection.getMetaData();
            ResultSet rs = dbInfo.getTables(null, null, "MARYCACHE", new String[]{"TABLE"});
            if (rs.next()) {
                // table exists 
            } else { 
                mustCreateTable = true;
            } 
        } 
        if (mustCreateTable) {
            String query = "CREATE CACHED TABLE MARYCACHE (id INTEGER IDENTITY, "

6
CodeRank
This code example shows how to use the following methods:getMetaData
		Connection nativeCon = doGetNativeConnection(targetCon);
		if (nativeCon == targetCon) {
			// We haven't received a different Connection, so we'll assume that there's 
			// some additional proxying going on. Let's check whether we get something 
			// different back from the DatabaseMetaData.getConnection() call. 
			DatabaseMetaData metaData = targetCon.getMetaData();
			// The following check is only really there for mock Connections 
			// which might not carry a DatabaseMetaData instance. 
			if (metaData != null) {
				Connection metaCon = metaData.getConnection();
				if (metaCon != null && metaCon != targetCon) {
					// We've received a different Connection there: 
					// Let's retry the native extraction process with it. 
					nativeCon = doGetNativeConnection(metaCon);
				} 
			} 
		} 
		return nativeCon;
	} 
 
6
CodeRank
This code example shows how to use the following methods:close, createStatement, getMetaData
    } 
 
    public void tearDown() throws Exception { 
        try { 
            conn = Support_SQL.getConnection();
            meta = conn.getMetaData();
            statement = conn.createStatement();
            deleteTestTables(); 
        } catch (SQLException e) {
            System.out.println("Error in teardown: "+e.getMessage());
        } finally { 
            try { 
                conn.close();
            } catch (SQLException e) {
            } 
        } 
        super.tearDown(); 
    } 
 
    private void createTestTables() { 
6
CodeRank
This code example shows how to use the following methods:createStatement, getMetaData
        ResultSet rs = null;
        Statement stmt = null;
        try { 
 
            dbConnection = dataSource.getConnection();
            DatabaseMetaData dbmd = dbConnection.getMetaData();
            rs = dbmd.getTables(null, null, "USER_MGT_PROPERTIES", null);
            stmt =
                dbConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
 
            if (rs.next() == false) {
 
                stmt.executeUpdate(CREATE_TABLE);
 
                dbConnection.commit();
            } else { 
                // TODO 
            } 
 
        } finally { 

6
CodeRank
This code example shows how to use the following methods:getMetaData
	public UpgradeOptimizedConnectionHandler(Connection connection)
		throws SQLException {
 
		_connection = connection;
 
		DatabaseMetaData metaData = _connection.getMetaData();
 
		String productName = metaData.getDatabaseProductName();
 
		if (productName.equals("Microsoft SQL Server")) {
			_useUpgradeOptimizedPreparedStatementHandler = true;
		} 
		else { 
			_useUpgradeOptimizedPreparedStatementHandler = false;
		} 
	} 
 
	@Override 
	public Object invoke(Object proxy, Method method, Object[] arguments)
		throws Throwable {
6
CodeRank
getMetaData Method Overview
Retrieves a DatabaseMetaData object that contains metadata about the database to which this Connection object represents a connection.
See Code Examples for other Java 8 Connection Methods: