Guest User

Untitled

a guest
Dec 3rd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.96 KB | None | 0 0
  1. private void cmdSaveActionPerformed(java.awt.event.ActionEvent evt) {
  2.          // Code staets here
  3.          // NOTE : MAKE NECESSARY CHANGES TO THE textfileds variable name,and change gender into combobox box, like how I did in class
  4.          
  5.         String Batch_No = txtBatch.getText();
  6.         String Name_of_patient = txtName.getText();
  7.         String Age = txtAge.getText();
  8.         String Location = (String)cmbLocation.getSelectedItem();
  9.         String Gender= (String)cmbGen.getSelectedItem(); // Change the two radio buttons male and female into a comobox, and add values 'male' & 'female'
  10.         String Medicine_name = txtmedicine.getText();
  11.         String Price = txtPrice.getText();
  12.         String Discount = txtDis.getText();
  13.         String Net = txtNet.getText();
  14.         if(optCash.isSelected()){
  15.             String Mode = "Cash";
  16.             try{
  17.             Class.forName("java.sql.Driver");
  18.             conn = DriverManager.getConnection("jdbc:mysql://localhost/<database-name>","root","<password>");
  19.             stmt = conn.createStatement();
  20.             stmt.executeUpdate("insert into <table-name> values('"+Batch_no+"','"+Name_of_patient+"','"+Age+"','"+Location+"','"+Gender+"','"+Medicine_name+"','"+Price+"','"+Mode+"','"+Discount+"','"+Net+"');");
  21.             stmt.close();
  22.             conn.close();
  23.             JOptionPane.showMessageDialog(null, "Saved");
  24.         }
  25.         catch(Exception e){
  26.             JOptionPane.showMessageDialog(null, e);
  27.         }
  28.         }
  29.         else if(optCredit.isSelected()){
  30.             String Mode = "Credit";
  31.             try{
  32.             Class.forName("java.sql.Driver");
  33.             conn = DriverManager.getConnection("jdbc:mysql://localhost/<database-name>","root","<password>");
  34.             stmt = conn.createStatement();
  35.             stmt.executeUpdate("insert into <table-name> values('"+Batch_no+"','"+Name_of_patient+"','"+Age+"','"+Location+"','"+Gender+"','"+Medicine_name+"','"+Price+"','"+Mode+"','"+Discount+"','"+Net+"');");
  36.             stmt.close();
  37.             conn.close();
  38.             JOptionPane.showMessageDialog(null, "Saved");
  39.         }
  40.         catch(Exception e){
  41.             JOptionPane.showMessageDialog(null, e);
  42.         }
  43.         }
  44.         else if(optCheque.isSelected()){
  45.             String Mode = "Cheque";
  46.             try{
  47.             Class.forName("java.sql.Driver");
  48.             conn = DriverManager.getConnection("jdbc:mysql://localhost/<database-name>","root","<password>");
  49.             stmt = conn.createStatement();
  50.             stmt.executeUpdate("insert into <table-name> values('"+Batch_no+"','"+Name_of_patient+"','"+Age+"','"+Location+"','"+Gender+"','"+Medicine_name+"','"+Price+"','"+Mode+"','"+Discount+"','"+Net+"');");
  51.             stmt.close();
  52.             conn.close();
  53.             JOptionPane.showMessageDialog(null, "Saved");
  54.         }
  55.         catch(Exception e){
  56.             JOptionPane.showMessageDialog(null, e);
  57.         }
  58.         }
  59.         //END OF CODING
  60.         //SEND SCREENSHOT IF NOT WORKING
  61.        
  62.     }
Add Comment
Please, Sign In to add comment