我有这段代码,我想在一个表中的 jtable 中显示 2 行。
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);
}
}
我收到这个错误
com.microsoft.sqlserver.jdbc.SQLServerException: The column name Pro_Price
is not valid.
我认为他希望从我的表格中添加其他行?我有没有正确的代码,所以我只能从特定的行中获取文本,或者可能是可以给我这个列的 sqlquery。因为这个列已经有价格,所以我只希望它们出现在我的 jtable ty 中!
最佳答案
这不是很明显吗,因为您根本没有根据以下查询获取该列。
SELECT Pro_Id, Pro_Name FROM Products
如果您确实需要获取该列rss.getString("Pro_Price")
,则在您的查询中包含该列
SELECT Pro_Id, Pro_Name, Pro_Price,
Pro_Quantity, Pro_Supplier_id, Pro_Tax
FROM Products
关于java - 我如何从一个表中调用 2 行以显示在 jtable 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39329823/