Hi, im a student doing a project on attendance system.... i have problem where the text entered (username)from formA jTextField1 need to pass to FormB in order to the combo box in FormB shows(subject,course,time) that correspond to the username was entered in Forma....i have try it....but got error...

Here is the code...it is not full code..

FormA

//value1 as username that entered

String value1=jTextField1.getText();
.....

public String getData()
    {
      return this.jTextField1.getText();
    }

FormB

.....
FormA page = new FormA(); 

String user = page.getData();

 try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\\Users\\sumathi\\Documents\\BDdatabase.accdb;}";
        Connection con = DriverManager.getConnection(url);
        Statement st=con.createStatement();
   ResultSet rs=st.executeQuery(" select * from Course where Staff_ID = '" +user+"'");
        // JOptionPane.showMessageDialog(null,"stupid","Error",JOptionPane.ERROR_MESSAGE);
//load data from database table Course
         while(rs.next()){
          jComboBox1.addItem(rs.getString("Subject"));
          jComboBox2.addItem(rs.getString("Course"));
          jComboBox3.addItem(rs.getString("Time"));
            
            }
        }
        catch(Exception e){}
        
    }

please me give some solution....tq

Recommended Answers

All 2 Replies

Your overall approach, with the public getData is good. The problem lies in

FormA page = new FormA(); // displays a new copy of the form
String user = page.getData();  // gets the data immediately - before the user can enter anything!

Somewhere you should have a button or some such that the user presses after entering the data, and that's when the call to getData needs to be executed. Either formA needs a reference to formB, or formB needs a ref to the existing formA for that to work (ie you need to call getData on the existing form, not a new one)- details depend on exactly how you have structured the rest of your code.

thanks alot...Mr.JamesCherrill..
Its work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.