Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package pulseapp;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.Driver;
  10. import java.sql.DriverManager;
  11. import java.sql.ResultSet;
  12. import java.sql.SQLException;
  13. import java.sql.Statement;
  14. import java.util.logging.Level;
  15. import java.util.logging.Logger;
  16. import javax.swing.JOptionPane;
  17. import java.sql.*;
  18.  
  19. /**
  20. *
  21. * @author ASUS
  22. */
  23. public class ConnBD {
  24. Connection con = null ;
  25. PreparedStatement pst = null ;
  26. ResultSet rs=null ;
  27. Statement st;
  28.  
  29. public ConnBD() {
  30. try {
  31. Class.forName("com.mysql.cj.jdbc.Driver");
  32. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bd?serverTimezone=UTC","root","");
  33. st = con.createStatement();
  34. System.out.println("succes");
  35. }
  36.  
  37.  
  38.  
  39.  
  40. catch (Exception ex) {
  41. System.out.println("Error: " + ex);
  42. System.out.println("ylaaen din rabeek");
  43.  
  44. }
  45.  
  46. }
  47. public void ajouter(int IDBook,String Type,String Title,String Author,float Price,int Quantity) {
  48. try {
  49. st = con.createStatement();
  50. String sql = "INSERT INTO stock VALUES('"+IDBook+"','"+Type+"','"+Title+"','"+Author+"','"+Price+"','"+Quantity+"')";
  51. st.executeUpdate(sql);
  52. }
  53. catch (Exception ex)
  54. {
  55. JOptionPane.showMessageDialog(null, ex);
  56. }
  57.  
  58. }
  59. public void supprimer(int IDBook1){
  60. try {
  61.  
  62. String query = "SELECT * FROM `stock` WHERE IDBook=?";
  63. pst = con.prepareStatement(query);
  64. pst.setInt(1, IDBook1);
  65. ResultSet rs = pst.executeQuery();
  66.  
  67.  
  68.  
  69. if(rs.next()){
  70. st = con.createStatement();
  71. String sql = "DELETE FROM `stock` WHERE IDBook="+IDBook1;
  72. st.executeUpdate(sql);
  73. JOptionPane.showMessageDialog(null, "Deleted Scuccessfully");
  74.  
  75.  
  76. }
  77. else {
  78. JOptionPane.showMessageDialog(null, "Key Invalid");
  79. }
  80. }
  81. catch (Exception ex)
  82. {
  83. JOptionPane.showMessageDialog(null, ex);
  84. }
  85. }
  86. public void update(int IDBook1,String Type1,String Title1,String Author1,float Price1,int Quantity1){
  87. try{
  88. String query = "SELECT * FROM `stock` WHERE IDBook=?";
  89. pst = con.prepareStatement(query);
  90. pst.setInt(1, IDBook1);
  91. ResultSet rs = pst.executeQuery();
  92.  
  93.  
  94.  
  95. if(rs.next()){
  96. st = con.createStatement();
  97. String sql ="UPDATE `stock` SET `Type`='"+Type1+"',`Title`='"+Title1+"',`Author`='"+Author1+"',`Price`='"+Price1+"',`Quantity`='"+Quantity1+"'WHERE `IDBook`='"+IDBook1+"'";
  98.  
  99.  
  100.  
  101.  
  102. st.executeUpdate(sql);
  103. JOptionPane.showMessageDialog(null, "Updated With Sucess");
  104. }
  105. else {
  106. JOptionPane.showMessageDialog(null, "Not Founded");
  107. }
  108. }
  109. catch (Exception ex)
  110. {
  111. JOptionPane.showMessageDialog(null, ex);
  112. }
  113.  
  114. }
  115.  
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement