<p>Create new database.</p>
@param pDbName database name without extension
@param pDbId database ID
@throws Exception - an exception
773132
@Override
  public final void createDatabase(final String pDbName,
    final int pDbId) throws Exception {
    String dbNm = this.databasePrefix + pDbName + ".sqlite";
    synchronized (this.factoryAppBeans) {
      if (!this.factoryAppBeans.getDatabaseName().equals(dbNm)) {
        this.factoryAppBeans.setDatabaseName(dbNm);
        this.factoryAppBeans.setNewDatabaseId(pDbId);
        this.factoryAppBeans.handleDatabaseChanged();
      }
    }
  }
1242096
public static function initPdoDatabase($config, $name)
    {
        try {
            $pdo = static::createPdoConnectionByConfig($config);
        } catch (PDOException $e) {
            throw new Exception('Cannon instantiate database connection: ' . $e->getMessage());
        }

        $pdo->uniqueName = $config['host'] . "-" . $config['db'];

        static::checkDebugBar($pdo, $name);

        return new RepositoryPDO($pdo, $name);
    }
97399
private void createOrOpenBDBDbs() throws Exception {
		// configuration for the mapping dbs
		DatabaseConfig dbConfig = new DatabaseConfig();
		dbConfig.setAllowCreate(true); // db will be created if it does not exist
		dbConfig.setReadOnly(readOnly);
		dbConfig.setTransactional(transactional);
		// create/open mapping dbs using config
		iidToIdDB = dbEnv.openDatabase(null, "idToName", dbConfig);

		// if countSizeOnLoad is true, the id-name mappings are counted and the loadCounter is initialized
		if (countSizeOnLoad) {
			System.out.println(new Date() + " counting index size started ");
			int idToNameMappings = (int) iidToIdDB.count();
			loadCounter = Math.min(idToNameMappings, maxNumVectors);
			System.out.println(new Date() + " counting index size ended ");
			System.out.println("Index size: " + loadCounter);
		}

		idToIidDB = dbEnv.openDatabase(null, "nameToId", dbConfig);

		if (useGeolocation) {// create/open geolocation db using config
			iidToGeolocationDB = dbEnv.openDatabase(null, "idToGeolocation", dbConfig);
		}

		if (useMetaData) {
			StoreConfig storeConfig = new StoreConfig(); // configuration of the entity store
			storeConfig.setAllowCreate(true); // store will be created if it does not exist
			storeConfig.setReadOnly(readOnly);
			storeConfig.setTransactional(transactional);
			iidToMetadataDB = new EntityStore(dbEnv, "idToMetadata", storeConfig);
			// int nameToMetadataMappings = (int) nameToMetadataBDB.getPrimaryIndex(String.class,
			// MediaFeedData.class).count(); // counting the size of an EntityStore
		}
	}
404597
@Override
  public final DatabaseWriterXml<RS> create(
    final Map<String, Object> pAddParam) throws Exception {
    DatabaseWriterXml<RS> dbWriterXmlFullImport = new DatabaseWriterXml<RS>();
    SrvEntityWriterXml srvEntityWriterXml = new SrvEntityWriterXml();
    SrvFieldWriterXmlStd srvFieldWriterXmlStd = new SrvFieldWriterXmlStd();
    srvFieldWriterXmlStd.setUtilXml(this.factoryAppBeans.lazyGetUtilXml());
    SrvFieldHasIdWriterXml srvFieldHasIdWriterXml =
      new SrvFieldHasIdWriterXml();
    srvFieldHasIdWriterXml.setUtilXml(this.factoryAppBeans.lazyGetUtilXml());
    srvEntityWriterXml.setUtlReflection(this.factoryAppBeans
      .lazyGetUtlReflection());
    Map<String, ISrvFieldWriter> fieldsWritersMap =
      new HashMap<String, ISrvFieldWriter>();
    fieldsWritersMap.put("SrvFieldWriterXmlStd", srvFieldWriterXmlStd);
    fieldsWritersMap.put("SrvFieldHasIdWriterXml", srvFieldHasIdWriterXml);
    srvEntityWriterXml.setFieldsWritersMap(fieldsWritersMap);
    srvEntityWriterXml.setMngSettings(this.factoryAppBeans
      .lazyGetMngSettingsGetDbCopy());
    dbWriterXmlFullImport.setLogger(this.factoryAppBeans.lazyGetLogger());
    dbWriterXmlFullImport.setSrvEntityWriter(srvEntityWriterXml);
    dbWriterXmlFullImport.setSrvDatabase(this.factoryAppBeans
      .lazyGetSrvDatabase());
    dbWriterXmlFullImport.setSrvOrm(this.factoryAppBeans.lazyGetSrvOrm());
    return dbWriterXmlFullImport;
  }
1190680
public void createTables( boolean makeIndexes ) throws Exception {
        database.executeInsertUpdateDeleteSql("DROP TABLE IF EXISTS " + TABLE_TILES);
        database.executeInsertUpdateDeleteSql("DROP TABLE IF EXISTS " + TABLE_METADATA);
        database.executeInsertUpdateDeleteSql(CREATE_TILES);
        database.executeInsertUpdateDeleteSql(CREATE_METADATA);
        if (makeIndexes) {
            createIndexes();
        }
    }
838206
@Override
	public void createDb(String dbName) {
	    String dbPath = toPath(dbName);
        LOGGER.info("Creating DB file: {}", dbPath);
        String folderPath = dbPath.substring(0, dbPath.lastIndexOf(File.separator));
        File dbDir = new File(folderPath);
        if (!dbDir.exists()) {
            createDbFolder(dbDir);
            LOGGER.info("Creating DB folder: {}", dbDir.getAbsolutePath());
        }

		
		//create files
		IOResourceProvider file = null;
		StorageRoot root = null;
		try {
			//DB file
			File dbFile = new File(toPath(dbName));
			if (dbFile.exists()) {
				throw DBLogger.newUser("ZOO: DB already exists: " + dbFile);
			}
			if (!dbFile.createNewFile()) {
				throw DBLogger.newUser("ZOO: Error creating DB file: " + dbFile);
			}
			FreeSpaceManager fsm = new FreeSpaceManager();
			root = new StorageRootFile(dbPath, "rw",
					ZooConfig.getFilePageSize(), fsm);
			file = root.createChannel();
			StorageChannelOutput out = file.createWriter(false);
			fsm.initBackingIndexNew(file);
			
			int headerPage = out.allocateAndSeek(PAGE_TYPE.DB_HEADER, 0);
			if (headerPage != 0) {
				throw DBLogger.newFatalInternal("Header page = " + headerPage);
			}
			int rootPage1 = out.allocateAndSeek(PAGE_TYPE.ROOT_PAGE, 0);
			int rootPage2 = out.allocateAndSeek(PAGE_TYPE.ROOT_PAGE, 0);

			//header: this is written further down
			
			//write User data
			int userData = out.allocateAndSeek(PAGE_TYPE.USERS, 0);
			
			
			//dir for schemata
			int schemaData = out.allocateAndSeekAP(PAGE_TYPE.SCHEMA_INDEX, 0, -1);
			//ID of next page
			out.writeInt(0);
			//Schema ID / schema data (page or actual data?)
			//0 for no more schemata
			out.writeInt(0);

			
			//dir for indices
			int indexDirPage = out.allocateAndSeek(PAGE_TYPE.INDEX_CATALOG, 0);
			//ID of next page
			out.writeInt(0);
			//Schema ID / attribute ID / index type / Page ID
			//0 for nor more indices
			out.writeInt(0);

			//OID index
			PagedOidIndex oidIndex = new PagedOidIndex(file);
//			bootstrapSchema(raf, oidIndex);
			int oidPage = file.writeIndex(oidIndex::write);

			//Free space index
			int freeSpacePg = file.writeIndex(fsm::write);
			
			//write header
			out.seekPageForWrite(PAGE_TYPE.DB_HEADER, headerPage);
			out.writeInt(DiskIO.DB_FILE_TYPE_ID);
			out.writeInt(DiskIO.DB_FILE_VERSION_MAJ);
			out.writeInt(DiskIO.DB_FILE_VERSION_MIN);
			out.writeInt(ZooConfig.getFilePageSize());
			out.writeInt(rootPage1);
			out.writeInt(rootPage2);
			
			writeRoot(out, rootPage1, 1, userData, oidPage, schemaData, indexDirPage, freeSpacePg, 
					fsm.getPageCount());
			writeRoot(out, rootPage2, 0, userData, oidPage, schemaData, indexDirPage, freeSpacePg, 
					fsm.getPageCount());
			
			
			file.close();
			file = null;
			root.close();
			root = null;
			out = null;


			//initial schemata
			Properties props = new ZooJdoProperties(dbName);
			PersistenceManagerFactory pmf = 
				JDOHelper.getPersistenceManagerFactory(props);
			PersistenceManager pm = pmf.getPersistenceManager();
			pm.currentTransaction().begin();
			
			ZooSchema schema = ZooJdoHelper.schema(pm);
			schema.addClass(PersistenceCapableImpl.class);
			schema.addClass(DBHashMap.class);
			schema.addClass(DBArrayList.class);
			
			pm.currentTransaction().commit();
			pm.close();
			pmf.close();
		} catch (IOException e) {
			e.printStackTrace();
			throw DBLogger.newUser("ERROR While creating database: " + dbPath, e);
		} finally {
			if (file != null) {
				try {
					file.close();
				} catch (JDOException e) {
					e.printStackTrace();
					//ignore
				}
			}
		}
	}
261468
public boolean renameTable(String tableName, String newTableName) throws DBException
    {
        try {
            if (DBConstants.TRUE.equals((String)this.getDatabase().getProperties().get(SQLParams.NO_PREPARED_STATEMENTS_ON_CREATE)))
                this.setStatement(null, DBConstants.SQL_CREATE_TYPE);
            if (this.getStatement(DBConstants.SQL_CREATE_TYPE) == null)
            	this.setStatement(((JdbcDatabase)this.getDatabase()).getJDBCConnection().createStatement(), DBConstants.SQL_CREATE_TYPE);

            String sql = "RENAME TABLE " + tableName + " TO " + newTableName;
            this.getStatement(DBConstants.SQL_CREATE_TYPE).execute(sql);
            
            if (DBConstants.TRUE.equals((String)this.getDatabase().getProperties().get(SQLParams.NO_PREPARED_STATEMENTS_ON_CREATE)))
                this.setStatement(null, DBConstants.SQL_CREATE_TYPE);
        } catch (SQLException e) {
            throw this.getDatabase().convertError(e);
        }
        return true;
    }
54793
public static Database createHiveDatabase(String dbName, CatalogDatabase db) {
		Map<String, String> props = db.getProperties();
		return new Database(
			dbName,
			db.getDescription().isPresent() ? db.getDescription().get() : null,
			null,
			props);
	}
1240705
@Override
    public void afterPropertiesSet() throws Exception {
        Connection conn = null;

        try {
            boolean createTables = true;

            try {
                conn = dataSource.getConnection();

                ResultSet rs = conn.getMetaData().getTables(conn.getCatalog(), null, "EVENTS_CUSTOMINFO", null);
                while (rs.next()) {
                    LOG.warning("Tables and indexes will not be created as they are already existing");
                    createTables = false;
                }
            } catch (SQLException e) {
                LOG.log(Level.WARNING, "Tables and indexes can not be created", e);
                createTables = false;
            }

            if (createTables) {
                ScriptRunner sr = new ScriptRunner(conn, false, false);
                sr.setLogWriter(null);
                sr.setErrorLogWriter(null);
                sr.runScript(new InputStreamReader(this.getClass().getResourceAsStream("/" + createSql)));
                if (createSqlInd != null && !createSqlInd.equals("")) {
                    sr.runScript(new InputStreamReader(this.getClass().getResourceAsStream("/" + createSqlInd)));
                } else {
                    LOG.warning("The script to create indexes has not been set. Indexes will not be created.");
                }
            }
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    LOG.warning("Unable to close JDBC connection.");
                }
            }
        }
    }
1073478
public void setupDb(boolean createDb, boolean createTables, boolean dropDb) throws Exception {

        if (m_setupBean.isInitialized()) {
            System.out.println("Setup-Bean initialized successfully.");
            CmsSetupDb db = new CmsSetupDb(m_setupBean.getWebAppRfsPath());
            try {
                // try to connect as the runtime user
                db.setConnection(
                    m_setupBean.getDbDriver(),
                    m_setupBean.getDbWorkConStr(),
                    m_setupBean.getDbConStrParams(),
                    m_setupBean.getDbWorkUser(),
                    m_setupBean.getDbWorkPwd(),
                    false);
                if (!db.noErrors()) {

                    // try to connect as the setup user
                    db.closeConnection();
                    db.clearErrors();
                    db.setConnection(
                        m_setupBean.getDbDriver(),
                        m_setupBean.getDbCreateConStr(),
                        m_setupBean.getDbConStrParams(),
                        m_setupBean.getDbCreateUser(),
                        m_setupBean.getDbCreatePwd());
                }
                if (!db.noErrors() || !m_setupBean.validateJdbc()) {
                    throw new DBException("DB connection test failed.", db.getErrors());
                }
            } finally {
                db.clearErrors();
                db.closeConnection();
            }
        }

        System.out.println("DB connection tested successfully.");

        CmsSetupDb db = null;
        boolean dbExists = false;
        if (m_setupBean.isInitialized()) {
            if (createDb || createTables) {
                db = new CmsSetupDb(m_setupBean.getWebAppRfsPath());
                // check if database exists
                if (m_setupBean.getDatabase().startsWith("oracle")
                    || m_setupBean.getDatabase().startsWith("db2")
                    || m_setupBean.getDatabase().startsWith("as400")) {
                    setWorkConnection(db);
                } else {
                    db.setConnection(
                        m_setupBean.getDbDriver(),
                        m_setupBean.getDbWorkConStr(),
                        m_setupBean.getDbConStrParams(),
                        m_setupBean.getDbCreateUser(),
                        m_setupBean.getDbCreatePwd(),
                        false);
                    dbExists = db.noErrors();
                    if (dbExists) {
                        db.closeConnection();
                    } else {
                        db.clearErrors();
                    }
                }
                if (!dbExists || dropDb) {
                    db.closeConnection();
                    if (!m_setupBean.getDatabase().startsWith("db2")
                        && !m_setupBean.getDatabase().startsWith("as400")) {
                        db.setConnection(
                            m_setupBean.getDbDriver(),
                            m_setupBean.getDbCreateConStr(),
                            m_setupBean.getDbConStrParams(),
                            m_setupBean.getDbCreateUser(),
                            m_setupBean.getDbCreatePwd());
                    }
                }
            }
        }
        if (!createDb && !createTables && !dbExists) {
            throw new Exception("You have not created the Alkacon OpenCms database.");
        }
        if (dbExists && createTables && !dropDb && (db != null)) {
            throw new Exception("You have selected to not drop existing DBs, but a DB with the given name exists.");
        }
        if (dbExists && createDb && dropDb && (db != null)) {
            // drop the DB
            db.closeConnection();
            db.setConnection(
                m_setupBean.getDbDriver(),
                m_setupBean.getDbCreateConStr(),
                m_setupBean.getDbConStrParams(),
                m_setupBean.getDbCreateUser(),
                m_setupBean.getDbCreatePwd());
            db.dropDatabase(m_setupBean.getDatabase(), m_setupBean.getReplacer());
            if (!db.noErrors()) {
                List<String> errors = new ArrayList<>(db.getErrors());
                db.clearErrors();
                throw new DBException("Error occurred while dropping the DB!", errors);
            }
            System.out.println("Database dropped successfully.");
        }

        if (createDb && (db != null)) {
            // Create Database
            db.createDatabase(m_setupBean.getDatabase(), m_setupBean.getReplacer());
            if (!db.noErrors()) {
                DBException ex = new DBException("Error occurred while creating the DB!", db.getErrors());
                db.clearErrors();
                throw ex;
            }
            db.closeConnection();
            System.out.println("Database created successfully.");
        }

        if (createTables && (db != null)) {
            setWorkConnection(db);
            //Drop Tables (intentionally quiet)
            db.dropTables(m_setupBean.getDatabase());
            db.clearErrors();
            db.closeConnection();
            // reopen the connection in order to display errors
            setWorkConnection(db);
            //Create Tables
            db.createTables(m_setupBean.getDatabase(), m_setupBean.getReplacer());
            if (!db.noErrors()) {
                DBException ex = new DBException("Error occurred while creating the DB!", db.getErrors());
                db.clearErrors();
                throw ex;
            }
            db.closeConnection();
            System.out.println("Tables created successfully.");
        }
        if (db != null) {
            db.closeConnection();
        }
        System.out.println("Database setup was successful.");
        m_context.stepForward();
    }
265675
public function createTable($tableName, $attributes)
    {
        try {
            $this->db->createTable($tableName, $attributes);
        } catch (\Exception $e) {
            throw new DbException($e->getMessage());
        }
    }
1337249
private DBHandling createDBHandling() throws BuildException
    {
        if ((_handling == null) || (_handling.length() == 0))
        {
            throw new BuildException("No handling specified");
        }
        try
        {
            String className     = "org.apache.ojb.broker.platforms."+
            					   Character.toTitleCase(_handling.charAt(0))+_handling.substring(1)+
            					   "DBHandling";
            Class  handlingClass = ClassHelper.getClass(className);

            return (DBHandling)handlingClass.newInstance();
        }
        catch (Exception ex)
        {
            throw new BuildException("Invalid handling '"+_handling+"' specified");
        }
    }
1339133
public void addPDatabase(PDatabase pDatabase)
    {
        Object strKey = pDatabase.getDatabaseKey();
        m_htDBList.put(strKey, pDatabase);
    }
639711
static final ZooRollingSession open(String dbName) {
        if (!ZooHelper.dbExists(dbName)) {
            // create database
            // By default, all database files will be created in %USER_HOME%/zoodb
            ZooHelper.createDb(dbName);
        }
		return new ZooRollingSession(dbName);
	}
1192423
private function createTable(): void
    {
        $statement = 'CREATE TABLE tests (
                          id INTEGER PRIMARY KEY,
                          command TEXT NOT NULL UNIQUE,
                          file_name TEXT NOT NULL,
                          reserved_by_process_id INTEGER,
                          completed INTEGER DEFAULT 0
                        )';

        if ($this->db->exec($statement) === false) {
            throw new Exception('Error while creating sqlite database table: ' . $this->db->errorCode());
        }
    }
924591
private DBConn createAndConnectConn(String keyspace) throws DBNotAvailableException, RuntimeException {
        DBConn dbConn = new DBConn(this, keyspace);
        connectDBConn(dbConn);
        return dbConn;
    }
465704
def create_jdbc_resource(name, server=None, **kwargs):
    '''
    
    '''
    defaults = {
        'description': '',
        'enabled': True,
        'id': name,
        'poolName': '',
        'target': 'server'
    }

    # Data = defaults + merge kwargs + poolname
    data = defaults
    data.update(kwargs)

    if not data['poolName']:
        raise CommandExecutionError('No pool name!')

    return _create_element(name, 'resources/jdbc-resource', data, server)