Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Can't retrieve Jtext Field values from another frame..

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Can't retrieve Jtext Field values from another frame..

    i m trying to retrieve jtext fields and combo box values from another frame and to put them in database but .getText() doesn't return anything please help me thanx in advance

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
             try{
           String sql = "select * from login where uid = ? and pass = ?";
           pst = con.prepareStatement(sql);
           pst.setString(1, jTextField1.getText());
           pst.setString(2, jTextField2.getText());
           rs = pst.executeQuery();
            if(rs.next()){
                JOptionPane.showMessageDialog(null, "username and password is correct ");
               if(products.addProduct==true){
                   products p = new products();
                   p.addProduct();
                   products.addProduct=false;
               }
            }else{
                JOptionPane.showMessageDialog(null, "username and password is not correct ");
     
            }
     
     
     
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
        }


    this is a password frame that calls addProduct() method from products class if password is correct.
    Here is addProduct() method


    public static void addProduct(){
        try {
                int Productid = getProductTypeId(combo_Type.getSelectedItem().toString());
     
                pst = con.prepareStatement("insert into product(pName,Product_type_id,pCost,pPrice,pQuantity,pModel,pCompany) values(?,?,?,?,?,?,?)");
                pst.setString(1, txt_Product_name.getText());
                JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText());
                pst.setInt(2, Productid);
                JOptionPane.showMessageDialog(null, "getProductTypeId is "+txt_Product_name.getText());
                pst.setString(3, txt_Product_cost.getText());
                JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText());
                pst.setString(4, txt_Product_price.getText());
                JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText());
                pst.setString(5, txt_Product_Quatity.getText());
                JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText());
                pst.setString(6, txt_Product_model.getText());
                JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText());
                pst.setString(7, combo_brand.getSelectedItem().toString());
                JOptionPane.showMessageDialog(null, "txt_Product_name is "+txt_Product_name.getText());
                pst.execute();
     
                JOptionPane.showMessageDialog(null, "Saved");
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);
            } finally {
                try {
                    pst.close();
     
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, e);
     
                }
     
            }
            Update_Table_Products();
    }
    Last edited by mehroz; March 26th, 2014 at 02:22 AM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Can't retrieve Jtext Field values from another frame..

    Welcome to the forum! Please read this topic to learn how to post code correctly and other useful info for new members.

    Use print statements or other debugging tools to determine the results of method calls on desired components. Then, if the contents are not being collected and reported properly, back up and find out why. Otherwise, post a workable example that demonstrates the problem with the least amount of code possible.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    mehroz (March 25th, 2014)

  4. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can't retrieve Jtext Field values from another frame..

    thanx for your reply GregBrannon i m using print statements in addProduct() method when it is called the method is invoked successfully but in this the print statements which shows the values of text fields and combo boxes returns default values , for example null for string and 0 for integers.
    Last edited by mehroz; March 25th, 2014 at 06:32 AM.

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Can't retrieve Jtext Field values from another frame..

    There aren't any obvious problems with the code you've posted. Post runnable code that demonstrates the problem. It also isn't clear how your question is related to the thread title, so it would be helpful if you'd describe or give an example of the overall design so that we can see how one container or component is gathering data (or trying to) from another.

  6. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can't retrieve Jtext Field values from another frame..

    Thanx GregBrannon again but i found the problem, the method addProduct() was not returning the values of text fields, i was invoking a static method using an instance of the class in which the method resides , now i corrected by invoking directly using just class name now its working fine ..and sorry for my bad English
     products p = new products();
                   p.addProduct();
                   products.addProduct=false;

    it was my first code and i make it write using

                   products .addProduct();
                   products.addProduct=false;

Similar Threads

  1. How to access derived class field values?
    By ehsansh in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 1st, 2013, 05:08 AM
  2. Unable to retrieve values from mySQL using JSP MVC application
    By jaltaie in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: August 31st, 2013, 03:10 PM
  3. Recurssion programming to retrieve inner values of objects
    By balajigoud in forum Member Introductions
    Replies: 1
    Last Post: June 22nd, 2013, 04:17 PM
  4. Create a JText field upon button click
    By jo15765 in forum AWT / Java Swing
    Replies: 3
    Last Post: May 28th, 2012, 07:06 PM
  5. retrieve data from database using Hashmap (multiple values in one key)
    By ashin12 in forum Collections and Generics
    Replies: 2
    Last Post: April 4th, 2012, 05:22 AM

Tags for this Thread