I want to populate List of tables as a dynamic checkbox using Jframe/Swing in netbeans. The count of table is not known as i am giving USER to select DB as well. Please help, below is code which is for populating list of tables as combo box
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: String dbValue=(String)jComboBox2.getSelectedItem(); String Connection = jTextField1.getText(); String User = jTextField2.getText(); char[] pwd = jPasswordField1.getPassword(); // TODO Auto-generated method stub //bt2.setEnabled(false); Object ob=evt.getSource(); if (ob == jButton2) {
/* String Connection = tf1.getText();
String User = tf2.getText();
char[] pwd = p1.getPassword();*/
System.out.println("**************");
try
{
String passwrd=String.valueOf(pwd);
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(Connection,User,passwrd);
Statement st=con.createStatement();
ResultSet rs2= st.executeQuery("SELECT Count(*) FROM DBA_TABLES where owner='"+dbValue+"'");
if(rs2.next()){
count=rs2.getInt(1);
}
generateCheckboxesDynamically(count);
System.out.println("Count="+count);
ResultSet rs1=st.executeQuery("select table_name from dba_tables where owner='"+dbValue+"'");
while(rs1.next())
{
for(int i=1;i<=count;i++){
JCheckBox jCheckBoxMenu=new JCheckBox("check"+i);
jCheckBoxMenu.setText(rs1.getString(1));
add(jCheckBoxMenu);
checks.add(jCheckBoxMenu);
jCheckBoxMenu.setVisible(true);
}
pack();
//JCheckBox ma=new JCheckBox;
String name = rs1.getString(1);
if (name.equals("")) {
jComboBox1.removeAll();
jComboBox1.addItem("");
jComboBox1.setVisible(false);
}
else {
jComboBox1.addItem(rs1.getString(1));
System.out.println(rs1.getString(1));
jComboBox1.setVisible(true);
}
jTextField1.setEnabled(false);
jTextField2.setEnabled(false);
//tf3.setEnabled(false);
jButton1.setEnabled(false);
}
//String dbValue=(String)jComboBox1.getSelectedItem();
System.out.println("Selected DB=="+dbValue);
//bt2.setEnabled(true);
//bt1.removeActionListener(this);
}
catch (Exception ex)
{
System.out.println(ex);
}
}
}
Aucun commentaire:
Enregistrer un commentaire