Advertisement
Guest User

DBMS

a guest
May 9th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.21 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.sql.*;
  6. import java.util.Vector;
  7. //©SakibCSTE9th
  8. import javax.swing.*;
  9. import javax.swing.table.DefaultTableModel;
  10. public class main {
  11.  
  12.     public static final String URL="jdbc:mysql://localhost:3306/jdbcdemo";
  13.     public static final String username="root";
  14.     public static final String password="";
  15.     public static final String banani="©Sakib";
  16.     public static String A="";
  17.     public static String B="";
  18.     public static String P="";
  19.     public static String M="";
  20.     public static String D="";
  21.     static JFrame window=new JFrame("Book Management System");
  22.     static JPanel JP=new JPanel(null);
  23.     static ImageIcon ic=new ImageIcon(new main().getClass().getResource("image/Top.jpg"));
  24.     /**
  25.      * @param args
  26.      */
  27.     public static void main(String[] args) {
  28.         // TODO Auto-generated method stub
  29.  
  30.         home();
  31.        
  32.     }
  33.     static void heading()
  34.     {
  35.         window.setSize(400, 400);
  36.         window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37.        
  38.         JP.setBackground(Color.decode("#006DB6"));
  39.         window.getContentPane().add(JP);
  40.         JLabel JL=new JLabel();
  41.         JL.setBounds(0, 0, 400, 65);
  42.        
  43.         JL.setIcon(ic);
  44.         JP.add(JL);
  45.     }
  46.     static void home()
  47.     {
  48.         clear();
  49.         heading();
  50.         final JButton Add=new JButton("Add");
  51.         Add.setBounds(120, 70, 150, 30);
  52.         JP.add(Add);
  53.         final JButton View=new JButton("View One");
  54.         View.setBounds(120, 110, 150, 30);
  55.         JP.add(View);
  56.         final JButton ViewAll=new JButton("View All");
  57.         ViewAll.setBounds(120, 150, 150, 30);
  58.         JP.add(ViewAll);
  59.         final JButton Edit=new JButton("Edit");
  60.         Edit.setBounds(120, 190, 150, 30);
  61.         JP.add(Edit);
  62.         final JButton Delete=new JButton("Delete");
  63.         Delete.setBounds(120, 230, 150, 30);
  64.         JP.add(Delete);
  65.         JLabel CopN=new JLabel("©Md. Sakib Hossain");
  66.         CopN.setBounds(250, 330, 150, 20);
  67.         JP.add(CopN);
  68.         JLabel CopR=new JLabel("ASH1401064M");
  69.         CopR.setBounds(250, 350, 150, 20);
  70.         JP.add(CopR);
  71.         Add.addActionListener(new ActionListener()
  72.         {
  73.             public void actionPerformed(ActionEvent e)
  74.             {
  75.                 add();
  76.                 Add.removeActionListener(this);
  77.             }
  78.         });
  79.         Edit.addActionListener(new ActionListener()
  80.         {
  81.             public void actionPerformed(ActionEvent e)
  82.             {
  83.                 edit();
  84.             }
  85.         });
  86.         View.addActionListener(new ActionListener()
  87.         {
  88.             public void actionPerformed(ActionEvent e)
  89.             {
  90.                 view();
  91.                 View.removeActionListener(this);
  92.             }
  93.         });
  94.         ViewAll.addActionListener(new ActionListener()
  95.         {
  96.             public void actionPerformed(ActionEvent e)
  97.             {
  98.                 viewall();
  99.                 View.removeActionListener(this);
  100.             }
  101.         });
  102.         Delete.addActionListener(new ActionListener()
  103.         {
  104.             public void actionPerformed(ActionEvent e)
  105.             {
  106.                 delete();
  107.             }
  108.         });
  109.         window.setResizable(false);
  110.         window.setVisible(true);
  111.        
  112.     }
  113.     static void add()
  114.     {
  115.         clear();
  116.         heading();
  117.         JLabel BookName=new JLabel("Book Name:");
  118.         BookName.setBounds(10, 85, 120, 30);
  119.         BookName.setFont(new Font("Nyala",Font.BOLD,17));
  120.         BookName.setForeground(Color.decode("#FFFFFF"));
  121.         JP.add(BookName);
  122.         JLabel AuthorName=new JLabel("Author Name:");
  123.         AuthorName.setBounds(10, 125, 100, 30);
  124.         AuthorName.setFont(new Font("Nyala",Font.BOLD,17));
  125.         AuthorName.setForeground(Color.decode("#FFFFFF"));
  126.         JP.add(AuthorName);
  127.         JLabel Price=new JLabel("Price:");
  128.         Price.setBounds(10, 165, 100, 30);
  129.         Price.setFont(new Font("Nyala",Font.BOLD,17));
  130.         Price.setForeground(Color.decode("#FFFFFF"));
  131.         JP.add(Price);
  132.         JLabel Amount=new JLabel("Amount:");
  133.         Amount.setBounds(10, 205, 100, 30);
  134.         Amount.setFont(new Font("Nyala",Font.BOLD,17));
  135.         Amount.setForeground(Color.decode("#FFFFFF"));
  136.         JP.add(Amount);
  137.         JLabel Date=new JLabel("Date:");
  138.         Date.setBounds(10, 245, 100, 30);
  139.         Date.setFont(new Font("Nyala",Font.BOLD,17));
  140.         Date.setForeground(Color.decode("#FFFFFF"));
  141.         JP.add(Date);
  142.         final JTextField TB=new JTextField();
  143.         TB.setBounds(140, 85, 150, 25);
  144.         JP.add(TB);
  145.         final JTextField TA=new JTextField();
  146.         TA.setBounds(140, 125, 150, 25);
  147.         JP.add(TA);
  148.         final JTextField TP=new JTextField();
  149.         TP.setBounds(140, 165, 150, 25);
  150.         JP.add(TP);
  151.         final JTextField TM=new JTextField();
  152.         TM.setBounds(140, 205, 150, 25);
  153.         JP.add(TM);
  154.         final JTextField TD=new JTextField();
  155.         TD.setBounds(140, 245, 150, 25);
  156.         JP.add(TD);
  157.         final JButton Add=new JButton("Add");
  158.         Add.setBounds(220, 300, 100, 20);
  159.         JP.add(Add);
  160.         final JButton Cancel=new JButton("Cancel");
  161.         Cancel.setBounds(220, 330, 100, 20);
  162.         JP.add(Cancel);
  163.         Add.addActionListener(new ActionListener()
  164.         {
  165.             public void actionPerformed(ActionEvent e)
  166.             {
  167.                 B=TB.getText();
  168.                 A=TA.getText();
  169.                 String P=TP.getText();
  170.                 String M=TM.getText();
  171.                 String D=TD.getText();
  172.                 if(A.length()==0||B.length()==0||P.length()==0||M.length()==0||D.length()==0)
  173.                 {
  174.                     JOptionPane.showConfirmDialog(null,"No Box Can Be Empty","Success",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE);
  175.  
  176.                 }
  177.                 else{
  178.                     try {
  179.                         Connection SqlCon=DriverManager.getConnection(URL,username,password);
  180.                         Statement SqlState=SqlCon.createStatement();
  181.                         SqlState.executeUpdate("insert into book(name, author, price, amount, date) values('"+B+"','"+A+"','"+P+"','"+M+"','"+D+"')");
  182.                         JOptionPane.showConfirmDialog(null,"Book Added Successfully","Success",JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE);
  183.                     } catch (SQLException e1) {
  184.                         // TODO Auto-generated catch block
  185.                         e1.printStackTrace();
  186.                     }
  187.                 }
  188.  
  189. //                  Add.removeActionListener(this);
  190. //                  ©Sakib
  191.  
  192.             }
  193.         });
  194.        
  195.         Cancel.addActionListener(new ActionListener()
  196.         {
  197.             public void actionPerformed(ActionEvent e)
  198.             {
  199.                
  200.                     home();
  201.                     Cancel.removeActionListener(this);
  202.  
  203.             }
  204.         });
  205.        
  206.     }
  207.     static void view()
  208.     {
  209.         clear();
  210.         heading();
  211.         JLabel BookName=new JLabel("Book Name:");
  212.         BookName.setBounds(10, 85, 120, 30);
  213.         BookName.setFont(new Font("Nyala",Font.BOLD,17));
  214.         BookName.setForeground(Color.decode("#FFFFFF"));
  215.         JP.add(BookName);
  216.         JLabel AuthorName=new JLabel("Author Name:");
  217.         AuthorName.setBounds(10, 125, 100, 30);
  218.         AuthorName.setFont(new Font("Nyala",Font.BOLD,17));
  219.         AuthorName.setForeground(Color.decode("#FFFFFF"));
  220.         JP.add(AuthorName);
  221.         JLabel Price=new JLabel("Price:");
  222.         Price.setBounds(10, 165, 100, 30);
  223.         Price.setFont(new Font("Nyala",Font.BOLD,17));
  224.         Price.setForeground(Color.decode("#FFFFFF"));
  225.         JP.add(Price);
  226.         JLabel Amount=new JLabel("Amount:");
  227.         Amount.setBounds(10, 205, 100, 30);
  228.         Amount.setFont(new Font("Nyala",Font.BOLD,17));
  229.         Amount.setForeground(Color.decode("#FFFFFF"));
  230.         JP.add(Amount);
  231.         JLabel Date=new JLabel("Date:");
  232.         Date.setBounds(10, 245, 100, 30);
  233.         Date.setFont(new Font("Nyala",Font.BOLD,17));
  234.         Date.setForeground(Color.decode("#FFFFFF"));
  235.         JP.add(Date);
  236.        
  237.         final JTextField TB=new JTextField();
  238.         TB.setBounds(140, 85, 150, 25);
  239.         JP.add(TB);
  240.         final JTextField TA=new JTextField();
  241.         TA.setBounds(140, 125, 150, 25);
  242.         JP.add(TA);
  243.         JButton Search=new JButton("Search");
  244.         Search.setBounds(300, 85, 80, 25);
  245.         JP.add(Search);
  246.         final JButton Back=new JButton("Back");
  247.         Back.setBounds(300, 125, 80, 25);
  248.         JP.add(Back);
  249.         final JLabel TP=new JLabel("");
  250.         TP.setBounds(140, 165, 150, 25);
  251.         TP.setFont(new Font("Nyala",Font.BOLD,17));
  252.         TP.setForeground(Color.decode("#FFFFFF"));
  253.         JP.add(TP);
  254.         final JLabel TM=new JLabel("");
  255.         TM.setBounds(140, 205, 150, 25);
  256.         TM.setFont(new Font("Nyala",Font.BOLD,17));
  257.         TM.setForeground(Color.decode("#FFFFFF"));
  258.         JP.add(TM);
  259.         final JLabel TD=new JLabel("");
  260.         TD.setBounds(140, 245, 150, 25);
  261.         TD.setFont(new Font("Nyala",Font.BOLD,17));
  262.         TD.setForeground(Color.decode("#FFFFFF"));
  263.         JP.add(TD);
  264.  
  265.        Search.addActionListener(new ActionListener()
  266.         {
  267.             public void actionPerformed(ActionEvent e)
  268.             {
  269.                 B=TB.getText();
  270.                 A=TA.getText();
  271.                 P="";M="";D="";
  272.                 if(B.length()==0 || A.length()==0)
  273.                 {
  274.                     TB.setText("");
  275.                     TA.setText("");
  276.                      TP.setText("");
  277.                         TM.setText("");
  278.                         TD.setText("");
  279.                     JOptionPane.showMessageDialog(new JFrame(), "No Result Found", "Dialog",
  280.                             JOptionPane.ERROR_MESSAGE);
  281.                 }
  282.                 else {
  283.                     try {
  284.                         Connection SqlCon=DriverManager.getConnection(URL,username,password);
  285.                         Statement SqlState=SqlCon.createStatement();
  286.                         ResultSet rs=SqlState.executeQuery("Select * from book where name like'%"+B+"%' and author like '%"+A+"%'");       
  287.                         while(rs.next())
  288.                         {
  289.                             P=rs.getString("price");
  290.                             M=rs.getString("amount");
  291.                             D=rs.getString("date");
  292.                            
  293.                         }
  294.                     } catch (SQLException e1) {
  295.                         // TODO Auto-generated catch block
  296.                         e1.printStackTrace();
  297.                     }
  298.                     if(P.length()==0 && M.length()==0 && D.length()==0)
  299.                     {
  300.                          JOptionPane.showMessageDialog(new JFrame(), "No Result Found", "Dialog",
  301.                                     JOptionPane.ERROR_MESSAGE);
  302.                          TP.setText("");
  303.                             TM.setText("");
  304.                             TD.setText("");
  305.                             TA.setText("");
  306.                             TB.setText("");
  307.                     }
  308.                     else
  309.                        
  310.                     {
  311.                         TP.setText(P);
  312.                         TM.setText(M);
  313.                         TD.setText(D);
  314.                     }
  315.             }
  316. //                  Search.removeActionListener(this);
  317.  
  318.             }
  319.         });
  320.        
  321.        Back.addActionListener(new ActionListener()
  322.         {
  323.             public void actionPerformed(ActionEvent e)
  324.             {
  325.                
  326.                 home();
  327.                 Back.removeActionListener(this);
  328.             }
  329.         });
  330.     }
  331.     static void edit()
  332.     {
  333.         clear();
  334.         heading();
  335.         JLabel BookName=new JLabel("Book Name:");
  336.         BookName.setBounds(10, 85, 120, 30);
  337.         BookName.setFont(new Font("Nyala",Font.BOLD,17));
  338.         BookName.setForeground(Color.decode("#FFFFFF"));
  339.         JP.add(BookName);
  340.         JLabel AuthorName=new JLabel("Author Name:");
  341.         AuthorName.setBounds(10, 125, 100, 30);
  342.         AuthorName.setFont(new Font("Nyala",Font.BOLD,17));
  343.         AuthorName.setForeground(Color.decode("#FFFFFF"));
  344.         JP.add(AuthorName);
  345.         JLabel Price=new JLabel("Price:");
  346.         Price.setBounds(10, 165, 100, 30);
  347.         Price.setFont(new Font("Nyala",Font.BOLD,17));
  348.         Price.setForeground(Color.decode("#FFFFFF"));
  349.         JP.add(Price);
  350.         JLabel Amount=new JLabel("Amount:");
  351.         Amount.setBounds(10, 205, 100, 30);
  352.         Amount.setFont(new Font("Nyala",Font.BOLD,17));
  353.         Amount.setForeground(Color.decode("#FFFFFF"));
  354.         JP.add(Amount);
  355.         JLabel Date=new JLabel("Date:");
  356.         Date.setBounds(10, 245, 100, 30);
  357.         Date.setFont(new Font("Nyala",Font.BOLD,17));
  358.         Date.setForeground(Color.decode("#FFFFFF"));
  359.         JP.add(Date);
  360.        
  361.         final JTextField TB=new JTextField();
  362.         TB.setBounds(140, 85, 150, 25);
  363.         JP.add(TB);
  364.         final JTextField TA=new JTextField();
  365.         TA.setBounds(140, 125, 150, 25);
  366.         JP.add(TA);
  367.         JButton Search=new JButton("Search");
  368.         Search.setBounds(300, 85, 80, 25);
  369.         JP.add(Search);
  370.         final JButton Back=new JButton("Back");
  371.         Back.setBounds(300, 125, 80, 25);
  372.         JP.add(Back);
  373.         JP.add(TB);
  374.        
  375.         final JTextField TP=new JTextField();
  376.         TP.setBounds(140, 165, 150, 25);
  377.         JP.add(TP);
  378.         final JTextField TM=new JTextField();
  379.         TM.setBounds(140, 205, 150, 25);
  380.         JP.add(TM);
  381.         final JTextField TD=new JTextField();
  382.         TD.setBounds(140, 245, 150, 25);
  383.         JP.add(TD);
  384.         final JButton Up=new JButton("Update");
  385.         Up.setBounds(300, 300, 80, 25);
  386.         JP.add(Up);
  387.         Up.setEnabled(false);
  388.         Search.addActionListener(new ActionListener()
  389.         {
  390.             public void actionPerformed(ActionEvent e)
  391.             {
  392.                 B=TB.getText();
  393.                 A=TA.getText();
  394.                 P="";M="";D="";
  395.                 if(B.length()==0 || A.length()==0)
  396.                 {
  397.                     TB.setText("");
  398.                     TA.setText("");
  399.                      TP.setText("");
  400.                         TM.setText("");
  401.                         TD.setText("");
  402.                     JOptionPane.showMessageDialog(new JFrame(), "No Result Found", "Dialog",
  403.                             JOptionPane.ERROR_MESSAGE);
  404.                 }
  405.                 else {
  406.                     try {
  407.                         Connection SqlCon=DriverManager.getConnection(URL,username,password);
  408.                         Statement SqlState=SqlCon.createStatement();
  409.                         ResultSet rs=SqlState.executeQuery("Select * from book where name like'%"+B+"%' and author like '%"+A+"%'");       
  410.                         while(rs.next())
  411.                         {
  412.                             P=rs.getString("price");
  413.                             M=rs.getString("amount");
  414.                             D=rs.getString("date");
  415.                            
  416.                         }
  417.                     } catch (SQLException e1) {
  418.                         // TODO Auto-generated catch block
  419.                         e1.printStackTrace();
  420.                     }
  421.                     if(P.length()==0 && M.length()==0 && D.length()==0)
  422.                     {
  423.                          JOptionPane.showMessageDialog(new JFrame(), "No Result Found", "Dialog",
  424.                                     JOptionPane.ERROR_MESSAGE);
  425.                          TP.setText("");
  426.                             TM.setText("");
  427.                             TD.setText("");
  428.                             TA.setText("");
  429.                             TB.setText("");
  430.                             Up.setEnabled(false);
  431.                     }
  432.                     else
  433.                        
  434.                     {
  435.                         TP.setText(P);
  436.                         TM.setText(M);
  437.                         TD.setText(D);
  438.                         Up.setEnabled(true);
  439.                        
  440.                     }
  441.                 }
  442. //                  Search.removeActionListener(this);
  443.  
  444.             }
  445.         });
  446.        
  447.        Back.addActionListener(new ActionListener()
  448.         {
  449.             public void actionPerformed(ActionEvent e)
  450.             {
  451.                
  452.                 home();
  453.                 Back.removeActionListener(this);
  454.             }
  455.         });
  456.          Up.addActionListener(new ActionListener()
  457.             {
  458.                 public void actionPerformed(ActionEvent e)
  459.                 {
  460.                     String X="",Y="",Z="";
  461.                    
  462.                     X=TP.getText();
  463.                     Y=TM.getText();
  464.                     Z=TD.getText();
  465.  
  466. int opcion = JOptionPane.showConfirmDialog(null, "Want to Update?", "Confirm", JOptionPane.YES_NO_OPTION);
  467.  
  468. if (opcion == 0) { //The ISSUE is here
  469.     if(X.length()==0||Y.length()==0||Z.length()==0){
  470.         JOptionPane.showConfirmDialog(null,"No Box Can Be Empty","Error",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE);
  471.         TP.setText(P);
  472.         TM.setText(M);
  473.         TD.setText(D);
  474.        
  475.     }else{
  476.    
  477.     try {
  478.         Up.setEnabled(true);
  479.         Connection SqlCon=DriverManager.getConnection(URL,username,password);
  480.         Statement SqlState=SqlCon.createStatement();
  481.         SqlState.executeUpdate("update  book set price='"+X+"',amount='"+Y+"',date='"+Z+"' where name like'%"+B+"%' and author like '%"+A+"%'");   
  482.         JOptionPane.showConfirmDialog(null,"Book Updated Successfully","Success",JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE);
  483.         TP.setText(X);
  484.         TM.setText(Y);
  485.         TD.setText(Z);
  486.        
  487.     } catch (SQLException e1) {
  488.         // TODO Auto-generated catch block
  489.         e1.printStackTrace();
  490.     }
  491.     }
  492.    
  493. }
  494. else {
  495.    
  496.    
  497. }              
  498.                 }
  499.             });
  500.     }
  501.     static void delete()
  502.     {
  503.         clear();
  504.         heading();
  505.         JLabel BookName=new JLabel("Book Name:");
  506.         BookName.setBounds(10, 85, 120, 30);
  507.         BookName.setFont(new Font("Nyala",Font.BOLD,17));
  508.         BookName.setForeground(Color.decode("#FFFFFF"));
  509.         JP.add(BookName);
  510.         JLabel AuthorName=new JLabel("Author Name:");
  511.         AuthorName.setBounds(10, 125, 100, 30);
  512.         AuthorName.setFont(new Font("Nyala",Font.BOLD,17));
  513.         AuthorName.setForeground(Color.decode("#FFFFFF"));
  514.         JP.add(AuthorName);
  515.         JLabel Price=new JLabel("Price:");
  516.         Price.setBounds(10, 165, 100, 30);
  517.         Price.setFont(new Font("Nyala",Font.BOLD,17));
  518.         Price.setForeground(Color.decode("#FFFFFF"));
  519.         JP.add(Price);
  520.         JLabel Amount=new JLabel("Amount:");
  521.         Amount.setBounds(10, 205, 100, 30);
  522.         Amount.setFont(new Font("Nyala",Font.BOLD,17));
  523.         Amount.setForeground(Color.decode("#FFFFFF"));
  524.         JP.add(Amount);
  525.         JLabel Date=new JLabel("Date:");
  526.         Date.setBounds(10, 245, 100, 30);
  527.         Date.setFont(new Font("Nyala",Font.BOLD,17));
  528.         Date.setForeground(Color.decode("#FFFFFF"));
  529.         JP.add(Date);
  530.        
  531.         final JTextField TB=new JTextField();
  532.         TB.setBounds(140, 85, 150, 25);
  533.         JP.add(TB);
  534.         final JTextField TA=new JTextField();
  535.         TA.setBounds(140, 125, 150, 25);
  536.         JP.add(TA);
  537.         JButton Search=new JButton("Search");
  538.         Search.setBounds(300, 85, 80, 25);
  539.         JP.add(Search);
  540.         final JButton Back=new JButton("Back");
  541.         Back.setBounds(300, 125, 80, 25);
  542.         JP.add(Back);
  543.         final JLabel TP=new JLabel("");
  544.         TP.setBounds(140, 165, 150, 25);
  545.         TP.setFont(new Font("Nyala",Font.BOLD,17));
  546.         TP.setForeground(Color.decode("#FFFFFF"));
  547.         JP.add(TP);
  548.         final JLabel TM=new JLabel("");
  549.         TM.setBounds(140, 205, 150, 25);
  550.         TM.setFont(new Font("Nyala",Font.BOLD,17));
  551.         TM.setForeground(Color.decode("#FFFFFF"));
  552.         JP.add(TM);
  553.         final JLabel TD=new JLabel("");
  554.         TD.setBounds(140, 245, 150, 25);
  555.         TD.setFont(new Font("Nyala",Font.BOLD,17));
  556.         TD.setForeground(Color.decode("#FFFFFF"));
  557.         JP.add(TD);
  558.         final JButton Del=new JButton("Delete");
  559.         Del.setBounds(300, 300, 80, 25);
  560.         JP.add(Del);
  561.         Del.setEnabled(false);
  562.         Search.addActionListener(new ActionListener()
  563.         {
  564.             public void actionPerformed(ActionEvent e)
  565.             {
  566.                 B=TB.getText();
  567.                 A=TA.getText();
  568.                 P="";M="";D="";
  569.                 if(B.length()==0 || A.length()==0)
  570.                 {
  571.                     TB.setText("");
  572.                     TA.setText("");
  573.                      TP.setText("");
  574.                         TM.setText("");
  575.                         TD.setText("");
  576.                     JOptionPane.showMessageDialog(new JFrame(), "No Result Found", "Dialog",
  577.                             JOptionPane.ERROR_MESSAGE);
  578.                 }
  579.                 else {
  580.                     try {
  581.                         Connection SqlCon=DriverManager.getConnection(URL,username,password);
  582.                         Statement SqlState=SqlCon.createStatement();
  583.                         ResultSet rs=SqlState.executeQuery("Select * from book where name like'%"+B+"%' and author like '%"+A+"%'");       
  584.                         while(rs.next())
  585.                         {
  586.                             P=rs.getString("price");
  587.                             M=rs.getString("amount");
  588.                             D=rs.getString("date");
  589.                            
  590.                         }
  591.                     } catch (SQLException e1) {
  592.                         // TODO Auto-generated catch block
  593.                         e1.printStackTrace();
  594.                     }
  595.                     if(P.length()==0 && M.length()==0 && D.length()==0)
  596.                     {
  597.                          JOptionPane.showMessageDialog(new JFrame(), "No Result Found", "Dialog",
  598.                                     JOptionPane.ERROR_MESSAGE);
  599.                          TP.setText("");
  600.                             TM.setText("");
  601.                             TD.setText("");
  602.                             TA.setText("");
  603.                             TB.setText("");
  604.                             Del.setEnabled(false);
  605.                     }
  606.                     else
  607.                        
  608.                     {
  609.                         TP.setText(P);
  610.                         TM.setText(M);
  611.                         TD.setText(D);
  612.                         Del.setEnabled(true);
  613.                     }
  614.                 }
  615. //                  Search.removeActionListener(this);
  616.  
  617.             }
  618.         });
  619.        
  620.        Back.addActionListener(new ActionListener()
  621.         {
  622.             public void actionPerformed(ActionEvent e)
  623.             {
  624.                
  625.                 home();
  626.                 Back.removeActionListener(this);
  627.             }
  628.         });
  629.          Del.addActionListener(new ActionListener()
  630.             {
  631.                 public void actionPerformed(ActionEvent e)
  632.                 {
  633.  
  634.  
  635. int opcion = JOptionPane.showConfirmDialog(null, "Want to Delete?", "Confirm", JOptionPane.YES_NO_OPTION);
  636.  
  637. if (opcion == 0) { //The ISSUE is here
  638.    
  639.     try {
  640.         Connection SqlCon=DriverManager.getConnection(URL,username,password);
  641.         Statement SqlState=SqlCon.createStatement();
  642.         SqlState.executeUpdate("delete from book where name like'%"+B+"%' and author like '%"+A+"%'"); 
  643.         TA.setText("");
  644.         TB.setText("");
  645.         TP.setText("");
  646.         TM.setText("");
  647.         TD.setText("");
  648.         JOptionPane.showConfirmDialog(null,"Book Deleted Successfully","Success",JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE);
  649.         Del.setEnabled(false);
  650.     } catch (SQLException e1) {
  651.         // TODO Auto-generated catch block
  652.         e1.printStackTrace();
  653.     }
  654.    
  655. }
  656. else {
  657.    
  658.    
  659. }              
  660.                 }
  661.             });
  662.     }
  663.     static void viewall()
  664.     {
  665.         Vector data=new Vector();
  666.         Vector row=new Vector();
  667.         try {
  668.             Connection SqlCon=DriverManager.getConnection(URL,username,password);
  669.             Statement SqlState=SqlCon.createStatement();
  670.             ResultSet rs=SqlState.executeQuery("Select * from book");
  671.            
  672.  
  673.             while(rs.next())
  674.             {
  675.                 row=new Vector(5);
  676.                 for(int i=1;i<=5;i++)
  677.                 {
  678.                     row.add(rs.getString(i));
  679.                 }
  680.                 data.add(row);
  681.             }
  682.         } catch (SQLException e1) {
  683.             // TODO Auto-generated catch block
  684.             e1.printStackTrace();
  685.         }
  686.         window.setEnabled(false);
  687.         JFrame f;      
  688.         f=new JFrame("View All");      
  689.         Vector column=new Vector();  
  690.         column.addElement("Name");
  691.         column.addElement("Author");
  692.         column.addElement("Price");
  693.         column.addElement("Amount");
  694.         column.addElement("Date");
  695.         JTable jt=new JTable(data,column);    
  696.         jt.setBounds(30,40,200,300);          
  697.         JScrollPane sp=new JScrollPane(jt);    
  698.         jt.setEnabled(false);
  699.         f.setAlwaysOnTop (true);
  700.         f.add(sp);          
  701.         f.setSize(800,200);  
  702.         jt.getTableHeader().setReorderingAllowed(false);
  703.         f.setVisible(true);  
  704.         f.setResizable(false);
  705.         f.addWindowListener(new java.awt.event.WindowAdapter() {
  706.             public void windowClosing(java.awt.event.WindowEvent windowEvent) {
  707.                 window.setEnabled(true);
  708.             }
  709.         });
  710.        
  711.        
  712.     }
  713.     static void clear()
  714.     {
  715.         window.getContentPane().removeAll();
  716.         JP.removeAll();
  717.         window.getContentPane().add(JP);
  718.         window.getContentPane().revalidate();
  719.         JP.repaint();
  720.         JP.setBackground(Color.decode("#006DB6"));
  721.     }
  722. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement