java - Add values in JTable from Database Table -


this 1st class name connectiondbclass.java want save retrieve data database , store/show jtable.

public class connectiondbclass implements job {  public void execute(jobexecutioncontext arg0) throws jobexecutionexception { string servername = "192.168.0.1"; string portnumber = "1521"; string sid = "hifi"; string url = "jdbc:oracle:thin:@" + servername + ":" + portnumber + ":" + sid; string username = "courser_hotline"; string password = "courser_hotline"; string[] columnnames = {"command_name", "omc_name", "to_module", "start_time", "end_time", "status", "priority", "cmd_id"};  try {       drivermanager.registerdriver(new oracle.jdbc.driver.oracledriver());   //    system.out.println("connecting database...");       connection connection = drivermanager.getconnection(url, username, password);       statement statement = connection.createstatement();       string query = "select command_name, omc_name, to_module, start_time, end_time, status, priority, cmd_id sync_task_table"; //    string query = "select * sync_task_table";     resultset resultset = statement.executequery(query);     // create data     string datavalues[][] =   {     { resultset.getstring("command_name"), resultset.getstring( "omc_name"), resultset.getstring( "to_module"), resultset.getstring("start_time"),resultset.getstring("end_time"),resultset.getstring("status"),resultset.getstring("priority"),resultset.getstring("cmd_id") }    };   //   //// create new table instance  guiclass.table = new jtable( datavalues, columnnames );   }    catch (exception e) {       system.out.println("the exception raised is:" + e);   }   }  

}

this 2nd class name guiclass.java in class code of gui

public class guiclass extends jframe { static jframe frame; static jlabel formlabel; static jpanel panel1; static jpanel panel2; static jtextfield t1; static jcombobox selectomc; static jbutton run; static jpanel panel3; static defaulttablemodel model; public static jtable table; static jscrollpane tablescroll; static dimension tablepreferred;   public static void creategui() {     inilizationandlabelguivariables.initilization();     inilizationandlabelguivariables.labelform();    }  public static void main(string[] args) {     creategui();   }  } 

my 3rd class name inilizationandlabelguivariables.java in class initilize , label variable declared in guiclass.java class

 public class inilizationandlabelguivariables {  public static void initilization() {     guiclass.frame = new jframe("syncronization optimizer");     guiclass.panel1 = new jpanel(new borderlayout(5,5));      guiclass.panel2 = new jpanel(new flowlayout(flowlayout.right, 3,3));     guiclass.formlabel = new jlabel("syncronization optimizer tool");      guiclass.t1 = new jtextfield(23);     guiclass.selectomc = new jcombobox(connectiondb.omcname);     guiclass.run = new jbutton("  run  ");     guiclass.panel2 = new jpanel();     guiclass.model = new defaulttablemodel(connectiondbclass.datavalues, connectiondbclass.columnnames);     guiclass.table = new jtable(guiclass.model);     try {         // 1.6+         guiclass.table.setautocreaterowsorter(true);     } catch(exception continuewithnosort) {     }     guiclass.tablescroll = new jscrollpane(guiclass.table);     guiclass.tablepreferred = guiclass.tablescroll.getpreferredsize();     guiclass.tablescroll.setpreferredsize(         new dimension(guiclass.tablepreferred.width, guiclass.tablepreferred.height/3) );       guiclass.frame.setcontentpane(guiclass.panel1);      guiclass.frame.setbounds(150,100,570,491);     guiclass.frame.setresizable(false);     guiclass.frame.setdefaultcloseoperation(windowconstants.dispose_on_close);     guiclass.frame.setvisible(true); }   public static void labelform() {      guiclass.panel1.add(guiclass.panel2, borderlayout.north);      guiclass.panel2.add(guiclass.formlabel);      guiclass.panel2.add(guiclass.selectomc);      guiclass.panel1.add(guiclass.tablescroll);      guiclass.panel2.add(guiclass.table);     // gui.add( splitpane, borderlayout.center );  }  } 

please me stuck this.

  • jtable (its model) , table database has same structure, data stored in columns , rows

  • loop inside resultset , every row resultset add new vector<object> or new object[] table model or jtable.addrow defaulttablemodel

  • serch resultsettablemodel or better tablefromdatabase avoiding reinvent wheel


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -