@Override DataSource createDataSource() { EmbeddedDataSource dataSource = new EmbeddedDataSource(); dataSource.setUser(""); dataSource.setPassword(""); dataSource.setDatabaseName("dbtest"); dataSource.setCreateDatabase("create"); dataSource.setConnectionAttributes("upgrade=true"); return dataSource; } };
/** * Set the user name used establish the connection. * This value is used if no connection information is supplied by the application * when attempting to create a connection. * * @param user the user name used to establish the connection; may be null */ public void setUserName(String user) { ds.setUser(user); }
Connection getConnection() throws SQLException, DAOConnection { EmbeddedDataSource ds = new EmbeddedDataSource(); ds.setDatabaseName(dbUri); ds.setPassword(password); ds.setUser(username); Connection conn = null; try { conn = ds.getConnection(); } catch (SQLException e) { // check if cannot connect due to "Another instance of // Derby may have already booted the database". // The error code of this exception is 45000. if (e.getNextException().getErrorCode() == 45000) { throw new DAOConnection(e.getNextException().getMessage()); } throw new SQLException(e); } conn.setSchema(schema); return conn; }
public DatabaseUtil(Credential cred, String baseDir, String bootPassword) { this.baseDir = baseDir; dataSource = new EmbeddedDataSource(); dataSource.setUser(cred.getUsername()); dataSource.setPassword(cred.getPassword()); dataSource.setDatabaseName(baseDir); if (!bootPassword.equals(NOT_ENCRYPTED)) { String connAtts = "dataEncryption=true;bootPassword=" + bootPassword; dataSource.setConnectionAttributes(connAtts); } jdbcTemplate = new JdbcTemplate(dataSource); }