List of usage examples for java.sql DatabaseMetaData getUserName
String getUserName() throws SQLException;
From source file:uk.ac.ebi.bioinvindex.utils.test.DBUnitTest.java
/** * Creates a new database connection to be used by DbUnit, used {@link #initDataSet()} and {@link #afterTestProcessing()}. * @throws SQLException //from www .java 2s. co m * */ protected IDatabaseConnection createDbUnitConnection() throws SQLException, DatabaseUnitException { IDatabaseConnection dbUnitCon = new DatabaseConnection(connection); DatabaseConfig config = dbUnitCon.getConfig(); DatabaseMetaData dbmsMeta = connection.getMetaData(); String dbmsName = dbmsMeta.getDatabaseProductName().toLowerCase(); String dbmsCatalog = connection.getCatalog(); if (dbmsCatalog == null) // Let's try with the user name dbmsCatalog = dbmsMeta.getUserName().toUpperCase(); IDataTypeFactory dtf = new DefaultDataTypeFactory(); if (dbmsName.contains("h2")) dtf = new H2DataTypeFactory(); else if (dbmsName.contains("mysql")) dtf = new MySqlDataTypeFactory(); else if (dbmsName.contains("oracle")) dtf = new Oracle10DataTypeFactory(); else System.out.println("WARNING: Don't know which DBUnit DataType factory to use with '" + dbmsName + ", hope the default works"); config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, dtf); return dbUnitCon; }