我的jTable在插入或更新按钮后没有更新我的数据。我的jFrame有两个用于刷新我的表的函数。我的第一个函数运行良好,但我的第二个函数不是
这是我的第一个功能正常的
public void executeSQLQuery (String query,String message) {
Connection con =getConnection();
Statement stt;
try{
stt =con.createStatement();
if((stt.executeUpdate(query))==1)
{
//refresh jtable data
DefaultTableModel model=(DefaultTableModel)jTable_Products.getModel();
model.setRowCount(0);
show_Products_in_Jtable();
JOptionPane.showMessageDialog(null,"Data "+message+" Succefully");
}else{
JOptionPane.showMessageDialog(null,"Data Not "+message+ "Error");
}
}catch (Exception ex){
ex.printStackTrace();
}
}
public void show_Products_in_Jtable(){
ArrayList<Update_del_insert_products> list= getproList();
DefaultTableModel model =(DefaultTableModel)jTable_Products.getModel();
Object[] row =new Object[7];
for(int i =0;i< list.size();i++)
{
row[0] = list.get(i).getpro_Id();
row[1] = list.get(i).getpro_Name();
row[2] = list.get(i).getpro_Price();
row[3] = list.get(i).getpro_Quantity();
row[4] = list.get(i).getpro_Supplier_id();
row[5] = list.get(i).getpro_Tax();
row[6] = list.get(i).getcat_productss();
model.addRow(row);
}
}
这是我的查询
private void AddProductActionPerformed(java.awt.event.ActionEvent evt) {
String query="INSERT INTO Products(Pro_Id ,Pro_Name,Pro_Price,Pro_Quantity,Pro_Supplier_id,Pro_Tax,Cat_products)VALUES ('"+Pro_Id.getText()+" ','"+Pro_Name.getText()+" ','"+Pro_Price.getText()+" ','"+Pro_Quantity.getText()+" ','"+Pro_Supplier_id.getText()+" ','"+Pro_Tax.getText()+" ','"+Cat_productss.getText()+" ') ";
executeSQLQuery(query,"Inserted");
}
这是我的第二个函数,它不刷新任何数据。任何想法我做错了什么?
public void SQLQuery (String qquery,String message) {
Connection con =getConnection();
Statement sptt;
try{
sptt =con.createStatement();
if((sptt.executeUpdate(qquery))==1)
{
//refresh jtable data
DefaultTableModel model=(DefaultTableModel)jTable_Cat.getModel();
model.setRowCount(0);
show_cat_in_Jtable();
JOptionPane.showMessageDialog(null,"Data "+message+" Succefully");
}else{
JOptionPane.showMessageDialog(null,"Data Not "+message+ "Error");
}
}catch (Exception ex){
ex.printStackTrace();
}
}
public void show_cat_in_Jtable(){
ArrayList<Insert_categories> list= getcatList();
DefaultTableModel model =(DefaultTableModel)jTable_Cat.getModel();
Object[] row =new Object[2];
for(int i =0;i< list.size();i++)
{
row[0] = list.get(i).getcat_id();
row[1] = list.get(i).getcat_products();
model.addRow(row);
}
}
这是我的查询
private void Add_CatActionPerformed(java.awt.event.ActionEvent evt) {
String qquery="INSERT INTO Categories(Cat_products)VALUES ('"+Cat_products.getText()+" ') ";
executeSQLQuery(qquery,"Inserted");
}