Solved

Seeing textfields

Posted on 2013-11-20
10
170 Views
Last Modified: 2013-12-02
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.getConnection();
            Statement st = (Statement) con.createStatement();
            String command = "SELECT * FROM seller WHERE name = " + "'" + entry +"'";
                 ResultSet rec = st.executeQuery ( command );
                 
            rec.next();            
           
            jTextField_dailySellerNumber.setText(rec.getString("number"));
            jTextField_dailySellerName.setText(rec.getString("name"));
            jTextField_dailySellerAddress1.setText(rec.getString("address1"));
            jTextField_dailySellerAddress2.setText(rec.getString("address2"));
            jTextField_dailySellerCity.setText(rec.getString("city"));
            jTextField_dailySellerState.setText(rec.getString("state"));
            jTextField_dailySellerZip.setText(rec.getString("zip"));
            jTextField_dailySellerMortgage.setText(rec.getString("mortgage"));
            jTextField_dailySellerComment.setText(rec.getString("comment"));
            jTextField_dailySellerHeadIn.setText(rec.getString("head"));
           
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,
                "SQLException Reading Daily Seller: " + ex.getMessage());
        }
    }      
   
}
0
Comment
Question by:sargent240
  • 5
  • 4
10 Comments
 
LVL 11

Expert Comment

by:Manish
ID: 39665047
First set the value in some object like Person.
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.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 39665639
You could pass a Map to that method
    public void populateInvName(Map<String, JTextComponent> fieldsMap) {
        final String[] FIELD_NAMES = {
                "number", "name", "address1", "address2", "city", "state", "zip",
                "mortgage", "comment", "head"
            };
...
        if (rs.next()) {
            for (int i = 0; i < FIELD_NAMES.length; i++) {
                fieldsMap.get(FIELD_NAMES[i])
                         .setText(rs.getString(FIELD_NAMES[i]));
            }
        }

Open in new window

0
 

Author Comment

by:sargent240
ID: 39670892
Thanks CEHJ! One question, What do I send to the method when I call it for Map<String and JTextComponent>fieldsMap.

Thanks, Cheers.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39671338
Well you need to create a Map of course with all your fields keyed by column name
0
 

Author Comment

by:sargent240
ID: 39672796
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!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:CEHJ
ID: 39672824
fieldsMap = new HashMap<String, JTextComponent>();
fieldsMap.put("number", tfNumber);
fieldsMap.put("name", tfName);
...

Open in new window

0
 

Author Comment

by:sargent240
ID: 39673622
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39673898
I used the code from your last post and got a:

cannot find symbol var variable
Please post, verbatim, the error you got. Of course, you would have to define your Map variable as an instance variable
0
 

Author Closing Comment

by:sargent240
ID: 39689086
I got it figured out.  Thanks!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39689546
:)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now