public void setPreselectedDB(String db) { boolean hasItem = false; for (int i = 0; i < jdbcCombo.getItemCount(); i++) { if (jdbcCombo.getItemAt(i) instanceof DatabaseConnection) { DatabaseConnection conn = (DatabaseConnection) jdbcCombo.getItemAt(i); if (conn.getDisplayName().equals(db) || conn.toString().equals(db)) { hasItem = true; break; } } } jdbcCombo.setSelectedItem(ConnectionManager.getDefault().getConnection(db)); jdbcCombo.setEnabled(!hasItem); }
/** Returns a list of jdbc drivers that need to be deployed. */ private List<FileObject> jdbcDriversToDeploy(Set<Datasource> datasources) { List<FileObject> jdbcDriverFiles = new ArrayList<FileObject>(); Collection<File> driverCP = getJDBCDriverClasspath(); for (Datasource datasource : datasources) { String className = datasource.getDriverClassName(); boolean exists = false; try { exists = Util.containsClass(driverCP, className); } catch (IOException e) { LOGGER.log(Level.INFO, null, e); } if (!exists) { for (DatabaseConnection databaseConnection : DatasourceHelper.findDatabaseConnections(datasource)) { JDBCDriver[] jdbcDrivers; JDBCDriver connDriver = databaseConnection.getJDBCDriver(); if (connDriver != null) { jdbcDrivers = new JDBCDriver[] {connDriver}; } else { // old fashioned way - fallback String driverClass = databaseConnection.getDriverClass(); jdbcDrivers = JDBCDriverManager.getDefault().getDrivers(driverClass); } for (JDBCDriver jdbcDriver : jdbcDrivers) { for (URL url : jdbcDriver.getURLs()) { FileObject file = URLMapper.findFileObject(url); if (file != null) { jdbcDriverFiles.add(file); } } } } } } return jdbcDriverFiles; }