George Kontonikolaou George Kontonikolaou - 1 year ago 66
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;
stt = connection.createStatement();
rss = stt.executeQuery(query);
Update_del_insert_products update_del_insert_products ;
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"));
}catch (Exception e){
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();




And i am getting this error 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 Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download