Search in sources :

Example 11 with FbDatabase

use of org.firebirdsql.gds.ng.FbDatabase in project jaybird by FirebirdSQL.

the class FBManager method createDatabase.

// Meaningful management methods
@Override
public void createDatabase(String fileName, String user, String password) throws Exception {
    try {
        IConnectionProperties connectionProperties = createDefaultConnectionProperties(user, password);
        connectionProperties.setDatabaseName(fileName);
        FbDatabase db = dbFactory.connect(connectionProperties);
        db.attach();
        // otherwise exit, database already exists
        if (forceCreate)
            db.dropDatabase();
        else {
            db.close();
            // database exists, don't wipe it out.
            return;
        }
    } catch (SQLException e) {
    // we ignore it
    }
    try {
        IConnectionProperties connectionProperties = createDefaultConnectionProperties(user, password);
        connectionProperties.setDatabaseName(fileName);
        connectionProperties.setConnectionDialect((short) dialect);
        if (getPageSize() != -1) {
            connectionProperties.getExtraDatabaseParameters().addArgument(ISCConstants.isc_dpb_page_size, getPageSize());
        }
        try (FbDatabase db = dbFactory.connect(connectionProperties)) {
            db.createDatabase();
        }
    } catch (Exception e) {
        log.error("Exception creating database", e);
        throw e;
    }
}
Also used : SQLException(java.sql.SQLException) FbDatabase(org.firebirdsql.gds.ng.FbDatabase) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) SQLException(java.sql.SQLException)

Example 12 with FbDatabase

use of org.firebirdsql.gds.ng.FbDatabase in project jaybird by FirebirdSQL.

the class FBManager method isDatabaseExists.

@Override
public boolean isDatabaseExists(String fileName, String user, String password) throws Exception {
    try {
        IConnectionProperties connectionProperties = createDefaultConnectionProperties(user, password);
        connectionProperties.setDatabaseName(fileName);
        FbDatabase db = dbFactory.connect(connectionProperties);
        db.attach();
        db.close();
        return true;
    } catch (Exception e) {
        return false;
    }
}
Also used : FbDatabase(org.firebirdsql.gds.ng.FbDatabase) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) SQLException(java.sql.SQLException)

Aggregations

FbDatabase (org.firebirdsql.gds.ng.FbDatabase)12 Test (org.junit.Test)7 FBConnection (org.firebirdsql.jdbc.FBConnection)6 SQLException (java.sql.SQLException)4 GDSHelper (org.firebirdsql.gds.impl.GDSHelper)3 IConnectionProperties (org.firebirdsql.gds.ng.IConnectionProperties)3 Connection (java.sql.Connection)2 FbTransaction (org.firebirdsql.gds.ng.FbTransaction)2 ResourceException (javax.resource.ResourceException)1 TransactionParameterBuffer (org.firebirdsql.gds.TransactionParameterBuffer)1 FbStatement (org.firebirdsql.gds.ng.FbStatement)1