Link to home
Start Free TrialLog in
Avatar of Zolf
ZolfFlag for United Arab Emirates

asked on

displaying data in Jtable error

hello there,

can anybody tell me what mistake i am doing in my code below.because i get an error saying - Can't get dslam collection from database : Invalid column name.
before that let me explain what i am trying to do.i have a table which stores details about a product.instead of showing the foreign key ids(which is of no use for the viewer) i am trying to get its value from its main table i.e where it is the primary key.so first i get the fks and do a select on their main method to get its name.then i am trying to display it in the table.

for (int i = 0; i < collect.size(); i++)
          {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode)collect.get(i);
                DslamRow row = (DslamRow)node.getUserObject();
                ResultSet rsBooks_Rec=null;
                ResultSet rsBooks_Rec1=null;
                try
                {
                      Connection connect = JFParentFrame.getDBConnection();
                      Statement st = connect.createStatement();
                      
                      
                      
                      int dState = row.getStateId().intValue();
                      int dBrand = row.getBid().intValue();
                      String brandQuery  = "SELECT brand FROM dslam_brands WHERE dslam_b_id ='" + dBrand + "'";
                      String stateQuery  = "SELECT eng_name FROM dslam_state WHERE state_id ='" + dState + "'";
                      rsBooks_Rec = st.executeQuery(brandQuery);
                        rsBooks_Rec.next();
                        
                        //String brand = rsBooks_Rec.getString("dslam_b_id");
                        String brand = rsBooks_Rec.getString("brand");
                        
                        rsBooks_Rec1 = st.executeQuery(stateQuery);
                        rsBooks_Rec1.next();
                        
                        String state = rsBooks_Rec1.getString("eng_name");
                
                
                model.addRow(new Object[] {row.getDslamId(),
                              row.getNetName(),
                              row.getOip(),
                              row.getOSerialNo(),
                              rsBooks_Rec1.getString("eng_name"),
                              rsBooks_Rec.getString("brand")
                      });
                }
                catch (SQLException sqle)
                {
                      System.err.println("Can't get dslam collection from database : " + sqle.getMessage());
                }
          }
Avatar of Zolf
Zolf
Flag of United Arab Emirates image

ASKER


basically i am trying to add data from 3 db tables into JTable
Avatar of Mayank S
One of the column names you have provided in the query is incorrect.
Print the stack-trace using sqle.printStackTrace () so you know which line it is occuring at, then you can find out the wrong column-name.
ASKER CERTIFIED SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can only have one result-set open on a statement at one time so you cannot use rsBooks_Rec1.getString("eng_name"), rsBooks_Rec.getString("brand") together. Since you are storing those values in temporary variables brand and state, you should use them.