title: How to use prepared statement
body: <p>Someone has suggested to use prepared statement but I don't know how to use it. What changes do I have to do in my code?</p>
  
  <pre><code>try
  {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      System.out.println("\n Driver loaded");
  
      Connection con = DriverManager.getConnection("jdbc:odbc:wanisamajDB");
  
      Statement stmt = con.createStatement();
      System.out.println("statement is created");
  
      // System.out.println(Integer.parseInt(cbregn.getSelectedItem().toString()));
  
      String qry = " UPDATE Registration1 SET RegistrationNo = '"+cbregn.getSelectedItem()+"',SeniorPerson = '"+cbnm.getSelectedItem()+"', NativePlace = '"+tfplace.getText()+"',Kul = '"+tfkul.getText()+"', Gotra = '"+tfgotra.getText()+"' ,KulSwami = '"+tfswami.getText()+"', ResidensialAddress = '"+taraddr.getText()+"' , PinCode = '"+tfpcd.getText()+"', STDcode = '"+tfstdcode.getText()+"',TelephoneNo = '"+tftele.getText()+"', MobileNo = '"+tfmno.getText()+"', Email = '"+tfemail.getText()+"',Website ='"+tfweb.getText()+"',Education ='"+tfedu.getText()+"',Branch ='"+tfbrch.getText()+"',BloodGroup ='"+cbbldgrp.getSelectedItem()+"' where SeniorPerson='" +cbnm.getSelectedItem().toString()+"'" ;
  
            stmt.executeUpdate(qry);
  
            JOptionPane.showMessageDialog(null,"RECORD IS UPDATED SUCCESSFULLY ");
            System.out.println("QUERY");       
  
            // cbregn.setEditable(false);
            cbnm.setEditable(false);
            tfplace.setEditable(false);
            tfkul.setEditable(false);
            tfgotra.setEditable(false);
            tfswami.setEditable(false);
            taraddr.setEditable(false);
            tfpcd.setEditable(false);
            tfstdcode.setEditable(false);
            tftele.setEditable(false);
            tfmno.setEditable(false);
            tfemail.setEditable(false);
            tfweb.setEditable(false);
            tfedu.setEditable(false);
            tfbrch.setEditable(false);
            cbbldgrp.setEditable(false);
            con.close();
            stmt.close();
          }
  //            catch(SQLException eM)
  //            {
  //            JOptionPane.showMessageDialog(null,"RECORD IS NOT FOUND ");
  //            }
          catch(Exception et)
          {
               et.printStackTrace();
            //  System.out.println("error:"+et.getMessage());
          }  
  </code></pre>