use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.
the class FBConnectionTest method testCharacterSetJavaNoWarning.
/**
* Test if explicitly specifying a connection character set does not add a warning (or exception) on the connection.
*/
@Test
public void testCharacterSetJavaNoWarning() throws Exception {
Properties props = getDefaultPropertiesForConnection();
props.remove("lc_ctype");
props.setProperty("charSet", "Cp1254");
try (Connection con = DriverManager.getConnection(getUrl(), props)) {
SQLWarning warnings = con.getWarnings();
assertNull("Expected no warning when specifying connection character set", warnings);
IConnectionProperties connectionProperties = con.unwrap(FirebirdConnection.class).getFbDatabase().getConnectionProperties();
assertEquals("Unexpected connection encoding", "WIN1254", connectionProperties.getEncoding());
}
}
use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.
the class FBConnectionTest method testCharacterSetFirebirdNoWarning.
/**
* Test if explicitly specifying a connection character set does not add a warning (or exception) on the connection.
*/
@Test
public void testCharacterSetFirebirdNoWarning() throws Exception {
Properties props = getDefaultPropertiesForConnection();
props.setProperty("lc_ctype", "WIN1252");
try (Connection con = DriverManager.getConnection(getUrl(), props)) {
SQLWarning warnings = con.getWarnings();
assertNull("Expected no warning when specifying connection character set", warnings);
IConnectionProperties connectionProperties = con.unwrap(FirebirdConnection.class).getFbDatabase().getConnectionProperties();
assertEquals("Unexpected connection encoding", "WIN1252", connectionProperties.getEncoding());
}
}
use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.
the class FBManager method dropDatabase.
@Override
public synchronized void dropDatabase(String fileName, String user, String password) throws Exception {
checkStarted();
try {
IConnectionProperties connectionProperties = createDefaultConnectionProperties(user, password);
connectionProperties.setDatabaseName(fileName);
FbDatabase db = dbFactory.connect(connectionProperties);
db.attach();
db.dropDatabase();
} catch (Exception e) {
log.error("Exception dropping database", e);
throw e;
}
}
use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.
the class FBManager method isDatabaseExists.
@Override
public synchronized boolean isDatabaseExists(String fileName, String user, String password) throws Exception {
checkStarted();
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;
}
}
use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.
the class FBManager method createDatabase.
// Meaningful management methods
@Override
public synchronized void createDatabase(String fileName, String user, String password) throws Exception {
checkStarted();
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.setSqlDialect(dialect);
if (getPageSize() != -1) {
connectionProperties.setIntProperty("page_size", getPageSize());
}
if (getDefaultCharacterSet() != null) {
connectionProperties.setProperty("set_db_charset", getDefaultCharacterSet());
}
if (forceWrite != null) {
connectionProperties.setBooleanProperty("force_write", forceWrite);
}
try (FbDatabase db = dbFactory.connect(connectionProperties)) {
db.createDatabase();
}
} catch (Exception e) {
log.error("Exception creating database", e);
throw e;
}
}
Aggregations