java - passing data from one frame and setting it in textfield in another frame retrieving corresponding data from database -
i working on netbeans project (java swings) using mysql @ ground. got struck in particular scenario.
i working jtable
in 1 frame, frame1
row has selected on 'onclick' action event.
the corresponding data table in background in mysql retrieved , data passed on frame, frame2
data set jtextfield
.
the table in frame1
contains few selected tuples of whole table maintained in database.
the following code snippets used :: database table name db_table
1- select data table in frame1
public static string table; public static int row; private void jtable1mouseclicked(java.awt.event.mouseevent evt) { // todo add handling code here: jbutton3.setenabled(true); row = jtable1.getselectedrow(); table = (jtable1.getmodel().getvalueat(row,0).tostring()); }
2- action event on button redirect frame2
private void jbutton4actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: frame2 ac =new frame2(); jdesktoppane1.add(ac); try { ac.setselectedrow(table); } catch (exception e) { // logger.getlogger(showp1.class.getname()).log(level.severe, null, ex); } ac.setvisible(true); }
3- method in frame2
void setselectedrow(string table) { try { //resultset resultset = null; system.out.print(table); rs = pst.executequery("select * db_table attr="+ table +""); //system.out.print(table); while (rs.next()) { system.out.print(table); //jtextfield1.settext(resultset.getstring(1)); //system.out.print(table); jtextfield1.settext(rs.getstring("attr")); } } catch (sqlexception ex) { logger.getlogger(addclient.class.getname()).log(level.severe, null, ex); } }
the data being printed in output console not being stored in text field in frame2
...
hope clear problem
any suggestions appreciated..
Comments
Post a Comment