java - How to iterate multiple data from DataBase showing in UI in Single Frame? -
suppose have data in data base , retrieving using query.
example:
select * acsuserdetail "+useranme+"= '"+arg+"' " system.out.print(" firstname = " + rs.getstring("firstname"));
this return 2 result i.e.:
firstname = anurag firstname = arvind
but when showing data in ui in jframe
opening 2 frames having 2 details , if more details there number of frame open. may because data coming database coming 1 one not in single shot. want information consolidate in single frame. code ui is:-
public uiforshowingdata(string data) { frame = new jframe("showing data"); frame.setdefaultcloseoperation(jframe.dispose_on_close); frame.setvisible(true); frame.setsize(300, 300); button = new jbutton("ok"); frame.setlayout(null); button.setbounds(250, 250, 40, 50); frame.add(button); system.out.println(data.length()); tx = new jtextfield(data); frame.add(tx); tx.setbounds(50, 50, 40, 50); button.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent arg0) { frame.dispose(); } }); }
please note unclear happening given code snippet in question. i'll take shot in dark , guess uiforshowingdata(string data)
method being called each record in result set obtained querying database.
something this:
while (rs.next()) { ... uiforshowingdata ui = new uiforshowingdata(rs.getstring("firstname")); ... }
this explain why there many frames opened records in data base. solve problem might consider use collection store several values , use collection show data in single jframe
. using jlist or jtable better choice display records using text fields.
off-topic
please note query vulnerable sql injection attaks. avoid may want try preparedstatement instead. example:
string query = "select * acsuserdetail useranme = ?"; preparedstatement pst = connection.preparestatement(query); pst.setstring(arg); // arg argument compare resultset rs = pst.executequery();
swing designed work layout managers , use of null
layout , methods such setbounds(...)
, setlocation(...)
, setxxxsize(...)
discouraged. swing tutorials:
although possible without layout manager, should use layout manager if @ possible. layout manager makes easier adjust look-and-feel-dependent component appearances, different font sizes, container's changing size, , different locales. layout managers can reused other containers, other programs.
see these topics:
Comments
Post a Comment