Add Category Or Courses in java NetBeans Desktop Application
public void addcategory(int id , String category_name , String DESC){ try{ Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/store_managment_system","root","root"); PreparedStatement pst = con.prepareStatement("Insert into category values(?,?,?)"); pst.setInt(1, id); pst.setString(2, category_name); pst.setString(3, DESC); int rowcount = pst.executeUpdate(); if(rowcount == 1){ JOptionPane.showMessageDialog(this,"Category created Successfull"); cleartable(); setcategory(); } else{ JOptionPane.showMessageDialog(this, "Category creating Failed"); } } catch(Exception e){ e.printStackTrace(); } }
Call Add Category behind Add Button
int id = Integer.parseInt(txt_id.getText()); String category = txt_category_name.getText(); String desc= txt_desciription.getText(); addcategory(id , category , desc);
Delete Category Or Courses in java NetBeans Desktop Application
public void deleterecords(int id ){ try{ Connection co = DriverManager.getConnection("jdbc:mysql://localhost:3306/store_managment_system","root", "root"); PreparedStatement pst =co.prepareStatement("delete from category where ID=?"); pst.setInt(1,id); int rowcount = pst.executeUpdate(); if(rowcount == 1) { JOptionPane.showMessageDialog(this," Category deleted sucessfully"); cleartable(); setcategory(); } else { JOptionPane.showMessageDialog(this, " Category deleted Failed"); } } catch(Exception e){ e.printStackTrace(); }}
Call Delete Category behind Delete Button
int id = Integer.parseInt(txt_id.getText()); deleterecords(id );
Update Category Or Courses in java NetBeans Desktop Application
public void updatecategory(int id , String cname , String desc){ try{ Connection co = DriverManager.getConnection("jdbc:mysql://localhost:3306/store_managment_system","root", "root"); PreparedStatement pst =co.prepareStatement("update category set Cname=?,desciription=? where ID=?"); pst.setString(1,cname); pst.setString(2, desc); pst.setInt(3,id); int rowcount = pst.executeUpdate(); if(rowcount == 1) { JOptionPane.showMessageDialog(this," Category updated sucessfully"); cleartable(); setcategory(); } else { JOptionPane.showMessageDialog(this, " Category updated Failed"); } } catch(Exception e){ e.printStackTrace(); }}
Call Update Category behind Update Button
int id = Integer.parseInt(txt_id.getText()); String category = txt_category_name.getText(); String desc= txt_desciription.getText(); updatecategory(id , category , desc);
Add code behind Tabel
int rowno = tbl_data.getSelectedRow(); TableModel model = tbl_data.getModel(); txt_id.setText((String) (String)model.getValueAt(rowno , 0)); txt_category_name .setText((String) (String)model.getValueAt(rowno , 1)); txt_desciription.setText((String) (String)model.getValueAt(rowno , 2));
0 Comments