Advertisement
Guest User

Untitled

a guest
Aug 9th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. private void RemoveButtonActionPerformed(java.awt.event.ActionEvent evt) {
  2.  
  3. String url = "jdbc:derby://localhost:1527/Customers";
  4. String username = "username";
  5. String password = "password";
  6.  
  7. try {
  8. Connection conn = DriverManager.getConnection(url, username, password);
  9. if (conn != null) {
  10. System.out.println("Connected");
  11.  
  12. String sql = "UPDATE STOCKn"
  13. + "SET NUMBERINSTOCK = NUMBERINSTOCK -"+RemoveTextField1.getText()+" n"
  14. + "WHERE UPPER(name)=?";
  15.  
  16. PreparedStatement statement = conn.prepareStatement(sql);
  17.  
  18. statement.setString(1, RemoveTextField1.getText());
  19. statement.setString(2, RemoveAnItemTextField.getText().toUpperCase());
  20.  
  21. int rowsUpdated = statement.executeUpdate();
  22.  
  23. if (rowsUpdated > 0)
  24. {
  25. JOptionPane.showMessageDialog(null,"That item has been updated successfully");
  26. }
  27. else
  28. {
  29. JOptionPane.showMessageDialog(null,"That item is either not in the database or you have entered the wrong information");
  30. }
  31. }
  32. }catch (SQLException ex)
  33. {
  34. JOptionPane.showMessageDialog(null,ex.getMessage());
  35. }
  36. ResultSet rs = null;
  37. PreparedStatement ps = null;
  38. try{
  39. Connection conn = DriverManager.getConnection(url, username, password);
  40. ps = conn.prepareStatement("select * from Stock");
  41. rs = ps.executeQuery();
  42.  
  43. SearchTable.setModel(DbUtils.resultSetToTableModel(rs));
  44. }catch(Exception ex){
  45. JOptionPane.showMessageDialog(null, ex.getMessage());
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement