List of usage examples for weka.experiment InstanceQuery isConnected
public boolean isConnected()
From source file:adams.gui.visualization.instance.InstanceExplorer.java
License:Open Source License
/** * pops up SQL Viewer for SQL statement. *//*w ww .ja v a 2s . c o m*/ public void loadDataFromDatabase() { InstanceQuery query; List<InstanceContainer> data; Instances dataset; Instance inst; int i; if (m_LoadFromDatabaseDialog == null) { if ((getParentFrame() != null) && (getParentFrame() instanceof JFrame)) m_LoadFromDatabaseDialog = new SqlViewerDialog((JFrame) getParentFrame()); else m_LoadFromDatabaseDialog = new SqlViewerDialog(null); } m_LoadFromDatabaseDialog.setVisible(true); if (m_LoadFromDatabaseDialog.getReturnValue() != JOptionPane.OK_OPTION) return; try { showStatus("Executing query: " + m_LoadFromDatabaseDialog.getQuery()); query = new InstanceQuery(); query.setDatabaseURL(m_LoadFromDatabaseDialog.getURL()); query.setUsername(m_LoadFromDatabaseDialog.getUser()); query.setPassword(m_LoadFromDatabaseDialog.getPassword()); query.setQuery(m_LoadFromDatabaseDialog.getQuery()); query.setSparseData(m_LoadFromDatabaseDialog.getGenerateSparseData()); if (query.isConnected()) query.disconnectFromDatabase(); query.connectToDatabase(); showStatus("Loading data..."); data = new ArrayList<>(); dataset = query.retrieveInstances(); for (i = 0; i < dataset.numInstances(); i++) { inst = new Instance(); inst.set(dataset.instance(i)); inst.setID(dataset.relationName() + "." + i); data.add(getContainerManager().newContainer(inst)); showStatus("Loading data " + (i + 1) + "/" + dataset.numInstances()); } loadData(dataset, data); } catch (Exception e) { GUIHelper.showErrorMessage(this, "Failed to load data from database:\n" + Utils.throwableToString(e), "Database error"); } showStatus(""); }