Zolf
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)co llect.get( i);
DslamRow row = (DslamRow)node.getUserObje ct();
ResultSet rsBooks_Rec=null;
ResultSet rsBooks_Rec1=null;
try
{
Connection connect = JFParentFrame.getDBConnect ion();
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("dsl am_b_id");
String brand = rsBooks_Rec.getString("bra nd");
rsBooks_Rec1 = st.executeQuery(stateQuery );
rsBooks_Rec1.next();
String state = rsBooks_Rec1.getString("en g_name");
model.addRow(new Object[] {row.getDslamId(),
row.getNetName(),
row.getOip(),
row.getOSerialNo(),
rsBooks_Rec1.getString("en g_name"),
rsBooks_Rec.getString("bra nd")
});
}
catch (SQLException sqle)
{
System.err.println("Can't get dslam collection from database : " + sqle.getMessage());
}
}
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)co
DslamRow row = (DslamRow)node.getUserObje
ResultSet rsBooks_Rec=null;
ResultSet rsBooks_Rec1=null;
try
{
Connection connect = JFParentFrame.getDBConnect
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("dsl
String brand = rsBooks_Rec.getString("bra
rsBooks_Rec1 = st.executeQuery(stateQuery
rsBooks_Rec1.next();
String state = rsBooks_Rec1.getString("en
model.addRow(new Object[] {row.getDslamId(),
row.getNetName(),
row.getOip(),
row.getOSerialNo(),
rsBooks_Rec1.getString("en
rsBooks_Rec.getString("bra
});
}
catch (SQLException sqle)
{
System.err.println("Can't get dslam collection from database : " + sqle.getMessage());
}
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can only have one result-set open on a statement at one time so you cannot use rsBooks_Rec1.getString("en g_name"), rsBooks_Rec.getString("bra nd") together. Since you are storing those values in temporary variables brand and state, you should use them.
ASKER
basically i am trying to add data from 3 db tables into JTable