George Kontonikolaou George Kontonikolaou - 2 months ago 11
Java Question

Ηow i can call 2 rows from one table to show up in jtable

I have this code and i want to show up 2 rows in jtable from one table.

public ArrayList<Update_del_insert_products> getproList()
{
ArrayList <Update_del_insert_products> proList =new ArrayList <Update_del_insert_products> ();
Connection connection =getConnection();

String query ="SELECT Pro_Id, Pro_Name FROM Products";
Statement stt;
ResultSet rss;
try{
stt = connection.createStatement();
rss = stt.executeQuery(query);
Update_del_insert_products update_del_insert_products ;
while(rss.next())
{
update_del_insert_products = new Update_del_insert_products (rss.getString("Pro_Id"),rss.getString("Pro_Name"),rss.getString("Pro_Price"),rss.getString("Pro_Quantity"),rss.getString("Pro_Supplier_id"),rss.getString("Pro_Tax"));
proList.add(update_del_insert_products);
}
}catch (Exception e){
e.printStackTrace();
}
return proList;
}
public void show_Products_in_Jtable(){
ArrayList<Update_del_insert_products> list= getproList();

DefaultTableModel model =(DefaultTableModel)jTable_Prordes.getModel();
Object[] row =new Object[2];
for(int i =0;i< list.size();i++)
{
row[0] = list.get(i).getpro_Id();
row[1] = list.get(i).getpro_Name();


model.addRow(row);

}

}


And i am getting this error

com.microsoft.sqlserver.jdbc.SQLServerException: The column name Pro_Price
is not valid.


i think he expect to add the other rows from my table ? is there i right code so i can gettext from only specific rows or maybe sqlquery that can bring me this columns .Cause this columns have already prices so i just want them to show up in my jtable ty !!

Answer

Isn't that pretty obvious since you are not fetching that column at all as per your below query.

SELECT Pro_Id, Pro_Name FROM Products

If you really need to fetch that column rss.getString("Pro_Price") then include that column in your query

SELECT Pro_Id, Pro_Name, Pro_Price,
Pro_Quantity, Pro_Supplier_id, Pro_Tax
FROM Products
Comments