[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

displaying data in Jtable error

Posted on 2006-05-14
5
Medium Priority
?
208 Views
Last Modified: 2010-03-31
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());
                }
          }
0
Comment
Question by:zolf
  • 4
5 Comments
 

Author Comment

by:zolf
ID: 16680130

basically i am trying to add data from 3 db tables into JTable
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16680226
One of the column names you have provided in the query is incorrect.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16680229
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.
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 1000 total points
ID: 16680243
>> model.addRow(new Object[] {row.getDslamId(),
>> row.getNetName(),
>> row.getOip(),
>> row.getOSerialNo(),
>> rsBooks_Rec1.getString("eng_name"),
>> rsBooks_Rec.getString("brand")
>> });

Make it:

model.addRow(new Object[] {row.getDslamId(),
                         row.getNetName(),
                         row.getOip(),
                         row.getOSerialNo(),
                         brand,
                         state
                   });

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16680300
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.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month18 days, 22 hours left to enroll

834 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