Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. package myshop.model;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10.  
  11. public class MyShopRepository {
  12. private MyShopRepository() throws SQLException{
  13. conn = DriverManager.getConnection("jdbc:mysql://localhost/myshop","root","2007991710126");
  14. }
  15. private static MyShopRepository instance;
  16. private Connection conn;
  17. public static MyShopRepository getInstance() throws SQLException{
  18. if(instance==null){
  19. instance = new MyShopRepository();
  20. }
  21. return instance;
  22. }
  23. public void editCategory(String description,String name,int id)throws SQLException{
  24. PreparedStatement ps = conn.prepareStatement("update category set name = ?,description = ? where id = ?");
  25. ps.setString(1, name);
  26. ps.setString(2,description);
  27. ps.setInt(3, id);
  28. ps.execute();
  29. }
  30.  
  31. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  32. try {
  33. int red = jTable1.getSelectedRow();
  34. DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();
  35. int id = Integer.parseInt(dtm.getValueAt(red, 0).toString());
  36. MainForm.mainForm.changeContent(new EditCategoryPanel(id));
  37. } catch(Exception ex){}
  38. }
  39.  
  40. public EditCategoryPanel(int id) throws SQLException {
  41. initComponents();
  42. MyShopRepository repo = MyShopRepository.getInstance();
  43. Category cat = repo.getCategory(id);
  44. tfName.setText(cat.name);
  45. tfDescription.setText(cat.description);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement