java - JTree data from database -


I am working on this example

I want to optimize it in a way such as data

  public person getGenealogyGraph () throws SQLException pulled from a table with {connection (folder_id, folder_name, parent_id [foreign keys to determine the parents]. string = "jdbc: mysql: // localhost: 3306 / "; string db =" java "; con = Drayvrmanejrktakshn (URL + dB," root "," "); Arerest list = new Arreist () trying; A. {String sql = "SELECT * from folder"; st = con.createStatement (); rs = st.executeQuery (SQL); list.add ( "current folders"), while (rsnext ()) {string folder name = rs.getString ( "folder_name"); list.add (folderName); // system.out.println (folder name); // person a1 = new person (folder name);}} catch (exception e) { System.out.println (e);} Rs.close (); st.close (); con.close (); object hierarchy [] = list.toArray (); for (Int i = 1; i & lt ; Hierarchy Long; I ++) {person A + i = new person (hierarchy [i]); }  

If I call it hardcode person a1 = new person ("Jack (great-grandfather)"); , it works fine. However, I wanted to put it in a loop with the variable: -

  object hierarchy [] = list.toArray (); For (Int i = 1; I & lt; hierarchy; long; i ++) {person A + i = new person (hierarchy [i]); }  

How can I combine variables I and "a" together? In PHP, we usually call them "." , Such as "A". $ I;

thanks :) Any other example on tree making from the database is greatly appreciated. Thanks in advance

I'm not sure what you are trying to do. But if you want to give a dynamic name your variables should be stored in associative array (java.util.Map) your object

  Show & lt; String, person & gt; Map = new hashmap & lt; String, person & gt; (); (...) map.put ("a" + i, new person (hierarchy [i]));  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -