Commit a6f75619 authored by Ondra's avatar Ondra
Browse files

Minor changes

parent 596d8960
......@@ -11,7 +11,13 @@ import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
......@@ -106,6 +112,82 @@ public class DatabaseBrowser extends JFrame {
refreshTable();
}
});
schemaBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent event) {
populateTableBox();
refreshTable();
}
});
tableBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent event) {
refreshTable();
}
});
return panel;
}
protected void populateCatalogBox() {
try {
DatabaseMetaData dmd = connection.getMetaData();
ResultSet rset = dmd.getCatalogs();
Vector values = new Vector();
while (rset.next()) {
values.addElement(rset.getString(1));
}
rset.close();
catalogBox.setModel(new DefaultComboBoxModel(values));
catalogBox.setSelectedItem(connection.getCatalog());
catalogBox.setEnabled(values.size() > 0);
} catch (Exception e) {
catalogBox.setEnabled(false);
}
}
protected void populateSchemaBox() {
try {
DatabaseMetaData dmd = connection.getMetaData();
ResultSet rset = dmd.getSchemas();
Vector values = new Vector();
while (rset.next()) {
values.addElement(rset.getString(1));
}
rset.close();
schemaBox.setModel(new DefaultComboBoxModel(values));
schemaBox.setSelectedItem(connection.getCatalog());
schemaBox.setEnabled(values.size() > 0);
} catch (Exception e) {
schemaBox.setEnabled(false);
}
}
protected void populateTableBox() {
try {
String[] types = {"TABLE"};
String catalog = connection.getCatalog();
String schema = (String) (schemaBox.getSelectedItem());
DatabaseMetaData dmd = connection.getMetaData();
ResultSet rset = dmd.getTables(catalog, schema, null, types);
Vector values = new Vector();
while (rset.next()) {
values.addElement(rset.getString(3));
}
rset.close();
tableBox.setModel(new DefaultComboBoxModel(values));
tableBox.setEnabled(values.size() > 0);
} catch (Exception e) {
tableBox.setEnabled(false);;
}
}
protected void refreshTable() {
String catalog = (catalogBox.isEnabled() ?
catalogBox.getSelectedItem().toString() :
null);
//String schema
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment