sargent240
asked on
Seeing textfields
following is my code to populate some textfields. The textfields are defined in the main program so I get errors saying can't find the textfields. How do I let this class know about the textfields. Thanks
public class populateInvName {
ConnectDatabase connectDatabase = new ConnectDatabase();
public Connection con;
public void populateInvName() {
try {
con = connectDatabase.getConnect ion();
Statement st = (Statement) con.createStatement();
String command = "SELECT * FROM seller WHERE name = " + "'" + entry +"'";
ResultSet rec = st.executeQuery ( command );
rec.next();
jTextField_dailySellerNumb er.setText (rec.getSt ring("numb er"));
jTextField_dailySellerName .setText(r ec.getStri ng("name") );
jTextField_dailySellerAddr ess1.setTe xt(rec.get String("ad dress1"));
jTextField_dailySellerAddr ess2.setTe xt(rec.get String("ad dress2"));
jTextField_dailySellerCity .setText(r ec.getStri ng("city") );
jTextField_dailySellerStat e.setText( rec.getStr ing("state "));
jTextField_dailySellerZip. setText(re c.getStrin g("zip"));
jTextField_dailySellerMort gage.setTe xt(rec.get String("mo rtgage"));
jTextField_dailySellerComm ent.setTex t(rec.getS tring("com ment"));
jTextField_dailySellerHead In.setText (rec.getSt ring("head "));
} catch (SQLException ex) {
JOptionPane.showMessageDia log(null,
"SQLException Reading Daily Seller: " + ex.getMessage());
}
}
}
public class populateInvName {
ConnectDatabase connectDatabase = new ConnectDatabase();
public Connection con;
public void populateInvName() {
try {
con = connectDatabase.getConnect
Statement st = (Statement) con.createStatement();
String command = "SELECT * FROM seller WHERE name = " + "'" + entry +"'";
ResultSet rec = st.executeQuery ( command );
rec.next();
jTextField_dailySellerNumb
jTextField_dailySellerName
jTextField_dailySellerAddr
jTextField_dailySellerAddr
jTextField_dailySellerCity
jTextField_dailySellerStat
jTextField_dailySellerZip.
jTextField_dailySellerMort
jTextField_dailySellerComm
jTextField_dailySellerHead
} catch (SQLException ex) {
JOptionPane.showMessageDia
"SQLException Reading Daily Seller: " + ex.getMessage());
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks CEHJ! One question, What do I send to the method when I call it for Map<String and JTextComponent>fieldsMap.
Thanks, Cheers.
Thanks, Cheers.
Well you need to create a Map of course with all your fields keyed by column name
ASKER
I have been looking around at how to set up the map and am not grasping what I need to do. Could you show me what the code should be as you did above? THANKS!
fieldsMap = new HashMap<String, JTextComponent>();
fieldsMap.put("number", tfNumber);
fieldsMap.put("name", tfName);
...
ASKER
I used the code from your last post and got a:
cannot find symbol var variable
on fieldsMap, tfNumber, and tfName.
I am struggling with the syntax, continuing to search through info on the web without much success. Besides the code I could use a little elementary discussion as to the parts involved. That would help a lot as to future use of the idea. Again Thank you very much.
cannot find symbol var variable
on fieldsMap, tfNumber, and tfName.
I am struggling with the syntax, continuing to search through info on the web without much success. Besides the code I could use a little elementary discussion as to the parts involved. That would help a lot as to future use of the idea. Again Thank you very much.
I used the code from your last post and got a:Please post, verbatim, the error you got. Of course, you would have to define your Map variable as an instance variable
cannot find symbol var variable
ASKER
I got it figured out. Thanks!
:)
put it in list.
Call this class from main class and get the list.
Iterate that list in main class and set it in jTextField.