Guest User

Untitled

a guest
Jan 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. class CategoryItem
  2. {
  3. int id;
  4. String name;
  5.  
  6. // add other fields if you want...
  7.  
  8. CategoryItem(int id, String name)
  9. {
  10. this.id = id;
  11. this.name = name;
  12. }
  13. public String toString()
  14. {
  15. return name;
  16. }
  17. }
  18.  
  19. public void LoadCategory()
  20. {
  21. try {
  22. Class.forName("com.mysql.jdbc.Driver");
  23. con1 = DriverManager.getConnection("jdbc:mysql://localhost/javapos","root","");
  24. insert = con1.prepareStatement("SELECT * FROM category");
  25. ResultSet rs = insert.executeQuery();
  26. jComboBox1.removeAllItems();
  27.  
  28. while(rs.next())
  29. {
  30. jComboBox1.addItem(CategoryItem(rs.getInt(1),rs.getString(2)));
  31. }
  32. }
  33. catch (Exception e) {
  34. }
  35. }
  36.  
  37. String name =txtproduct.getText();
  38. String dec =txtdec.getText();
  39.  
  40. CategoryItem item = (CategoryItem)jComboBox1.getSelectedItem();
  41.  
  42. Class.forName("com.mysql.jdbc.Driver");
  43. con1 = DriverManager.getConnection("jdbc:mysql://localhost/javapos","root","");
  44. insert = con1.prepareStatement("insert into product (productname,description,category)values(?,?,?)");
  45. insert.setString(1,name);
  46. insert.setString(2,dec);
  47. insert.setInt(3,item.id);
  48. insert.executeUpdate();
  49. JOptionPane.showMessageDialog(this, "Sucsessfully Saved");
Add Comment
Please, Sign In to add comment