mysql - Which is the best way to read values from database and display? -


am trying read values table in mysql database. table has 1 column , 4 rows. code below. know how read values. when @ code can understand able display 1 of value database, last value of table (the value in last row).

what need display values in table. not experienced programmer. tell me how can read , display values in table. there 1 more condition - need different button names each value in table, can add setonaction() function each button.

if there better idea using buttons, tell me too. shouldn't complex.

private vbox userselection() throws classnotfoundexception, sqlexception {      vbox vb1 = new vbox();     vb1.setpadding(new insets(40, 150, 20, 150));     vb1.setspacing(20);      button b = null;      text scenetitle2 = new text("choose account");     scenetitle2.setfont(font.font("tahoma", fontweight.bold, 20));      class.forname("com.mysql.jdbc.driver");     connect = drivermanager                 .getconnection("jdbc:mysql://localhost:3306/project?"                         + "user=root&password=virus");     statement = connect.createstatement();      rs = statement.executequery("select * user");      while (rs.next()) {          string username = rs.getstring("staffname");          b = new button(username);         b.setfont(font.font("calibri", fontweight.bold, 17));         b.setstyle(" -fx-base: #333333;");         b.settextfill(color.white);         b.setprefsize(150,30);      }      vb1.getchildren().addall(scenetitle2,b);             return vb1; } 

i'm not sure if follow problem but...

i see in while loop, overwrite button b object without adding vbox. last button object added. basicly have this:

vb1.getchildren().add(scenetitle2);   while (rs.next()) {      string username = rs.getstring("staffname");      b = new button(username);     b.setfont(font.font("calibri", fontweight.bold, 17));     b.setstyle(" -fx-base: #333333;");     b.settextfill(color.white);     b.setprefsize(150,30);      b.setonaction(...) //add handler button      vb1.getchildren().add(b); //add button object vbox inside loop } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -