Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void cmdSaveActionPerformed(java.awt.event.ActionEvent evt) {
- // Code staets here
- // NOTE : MAKE NECESSARY CHANGES TO THE textfileds variable name,and change gender into combobox box, like how I did in class
- String Batch_No = txtBatch.getText();
- String Name_of_patient = txtName.getText();
- String Age = txtAge.getText();
- String Location = (String)cmbLocation.getSelectedItem();
- String Gender= (String)cmbGen.getSelectedItem(); // Change the two radio buttons male and female into a comobox, and add values 'male' & 'female'
- String Medicine_name = txtmedicine.getText();
- String Price = txtPrice.getText();
- String Discount = txtDis.getText();
- String Net = txtNet.getText();
- if(optCash.isSelected()){
- String Mode = "Cash";
- try{
- Class.forName("java.sql.Driver");
- conn = DriverManager.getConnection("jdbc:mysql://localhost/<database-name>","root","<password>");
- stmt = conn.createStatement();
- stmt.executeUpdate("insert into <table-name> values('"+Batch_no+"','"+Name_of_patient+"','"+Age+"','"+Location+"','"+Gender+"','"+Medicine_name+"','"+Price+"','"+Mode+"','"+Discount+"','"+Net+"');");
- stmt.close();
- conn.close();
- JOptionPane.showMessageDialog(null, "Saved");
- }
- catch(Exception e){
- JOptionPane.showMessageDialog(null, e);
- }
- }
- else if(optCredit.isSelected()){
- String Mode = "Credit";
- try{
- Class.forName("java.sql.Driver");
- conn = DriverManager.getConnection("jdbc:mysql://localhost/<database-name>","root","<password>");
- stmt = conn.createStatement();
- stmt.executeUpdate("insert into <table-name> values('"+Batch_no+"','"+Name_of_patient+"','"+Age+"','"+Location+"','"+Gender+"','"+Medicine_name+"','"+Price+"','"+Mode+"','"+Discount+"','"+Net+"');");
- stmt.close();
- conn.close();
- JOptionPane.showMessageDialog(null, "Saved");
- }
- catch(Exception e){
- JOptionPane.showMessageDialog(null, e);
- }
- }
- else if(optCheque.isSelected()){
- String Mode = "Cheque";
- try{
- Class.forName("java.sql.Driver");
- conn = DriverManager.getConnection("jdbc:mysql://localhost/<database-name>","root","<password>");
- stmt = conn.createStatement();
- stmt.executeUpdate("insert into <table-name> values('"+Batch_no+"','"+Name_of_patient+"','"+Age+"','"+Location+"','"+Gender+"','"+Medicine_name+"','"+Price+"','"+Mode+"','"+Discount+"','"+Net+"');");
- stmt.close();
- conn.close();
- JOptionPane.showMessageDialog(null, "Saved");
- }
- catch(Exception e){
- JOptionPane.showMessageDialog(null, e);
- }
- }
- //END OF CODING
- //SEND SCREENSHOT IF NOT WORKING
- }
Add Comment
Please, Sign In to add comment