Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package myshop.model;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.List;
- public class MyShopRepository {
- private MyShopRepository() throws SQLException{
- conn = DriverManager.getConnection("jdbc:mysql://localhost/myshop","root","2007991710126");
- }
- private static MyShopRepository instance;
- private Connection conn;
- public static MyShopRepository getInstance() throws SQLException{
- if(instance==null){
- instance = new MyShopRepository();
- }
- return instance;
- }
- public void editCategory(String description,String name,int id)throws SQLException{
- PreparedStatement ps = conn.prepareStatement("update category set name = ?,description = ? where id = ?");
- ps.setString(1, name);
- ps.setString(2,description);
- ps.setInt(3, id);
- ps.execute();
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- int red = jTable1.getSelectedRow();
- DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();
- int id = Integer.parseInt(dtm.getValueAt(red, 0).toString());
- MainForm.mainForm.changeContent(new EditCategoryPanel(id));
- } catch(Exception ex){}
- }
- public EditCategoryPanel(int id) throws SQLException {
- initComponents();
- MyShopRepository repo = MyShopRepository.getInstance();
- Category cat = repo.getCategory(id);
- tfName.setText(cat.name);
- tfDescription.setText(cat.description);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement