Example : How to Stop Blank/Empty data or record Save in oracle 10g database.

private void jBtnRegSubmitActionPerformed(java.awt.event.ActionEvent evt) 
{           
          String TxtName = jTextField1.getText();

     //   if(TxtName.equals("")) or if(TxtName.length()==0) or if(TxtName.hashCode()==0 ) 
          or if(TxtName !=null && TxtName.equals(""))    
    
    if(TxtName.isEmpty()) 
     {        
            showMessageDialog(null,"Plese Enter Your Name");
            jTextField1.grabFocus();
            return;
     }
    if(jTextField1.getText().isEmpty()) 
     {        
            showMessageDialog(null,"Plese Enter Your Name");
            jTextField1.grabFocus();
            return;
     } 
    
        
    if(jXDatePicker1.getDate()==null)
      {
            showMessageDialog(null,"Please Select Any Date");
            jXDatePicker1.requestFocus();
            return;
      }        
        
    if(!jRadioButton1Male.isSelected())
      {
            showMessageDialog(null,"Please Select Any Gender");
            jRadioButton1Male.grabFocus();
            return;  
       }

     if((!jRadioButton1.isSelected())&&(!jRadioButton2.isSelected())&&(!jRadioButton3.isSelected()))
      {
           showMessageDialog(null,"Please Select Any Gender");
           jRadioButton1.grabFocus();
           return;
      }

     if((!jCheckBox1Matric.isSelected())
      {
           showMessageDialog(null,"Please Select Any Gender");
           jRadioButton1Male.grabFocus();
           return;
      }

     if((!jChkRegMatric.isSelected())&&(!jChkRegInter.isSelected())&&(!jChkRegGrad.isSelected())&& 
          (!jChkRegPg.isSelected()))
      {
            showMessageDialog(null,"Please Check Choice");
            return;
      }

     if(jComboBox1.getSelectedItem().equals("Select One"))
      {
           showMessageDialog(null,"Please Choose State");
           jCmbRegState.requestFocus();
           return;
      }
 
 Now we can put/write Save Code here.
}

Example : How to Save/Store data or record in oracle 10g database (1st Method).

// Write Java-Oracle 10g Connectivity Code here first properly/globally. 

private void jBtnRegSubmitActionPerformed(java.awt.event.ActionEvent evt) 
{
  int yn = showConfirmDialog(null,"Do You want to save the record!","Confirm 
              Save",YES_NO_OPTION);
   {
     if(yn == 0) 
      {
        String gender = " ";
        if(jRdbRegMale.isSelected())
          {
            gender="Male";
          }
        if(jRdbRegFemale.isSelected())
          {
            gender="Female";
          }
        if(jRdbRegOther.isSelected())
          {
            gender="Other";
          }
        
        String CmbState1 = (String)jCmbRegState.getSelectedItem();
        
        String ChkMatric = "";
        String ChkInter = "";
        String ChkGrad = "";
        String ChkPg = "";
        if(jChkRegMatric.isSelected())
          {
            ChkMatric="Matric";
          }
        else
          { 
            ChkMatric ="null";
          }
        if(jChkRegInter.isSelected())
          {
            ChkInter="Inter";
          }
        else
          { 
            ChkInter ="null";
          }
        if(jChkRegGrad.isSelected())
          {
            ChkGrad="Graduation";
          }
        else
          { 
            ChkGrad ="null";
          }
        if(jChkRegPg.isSelected())
          {
            ChkPg="PG";
          }
        else
          { 
            ChkPg ="null";
          }
        
        Date dd=jDtRegDob.getDate();             //import java.util.Date;
        Format xx= new SimpleDateFormat("dd-MMM-yyyy");        //import java.text.Format; & import 
                                                                 java.text.SimpleDateFormat;
        String pp =xx.format(dd);
                 
        String TxtSlno = jTxtRegSlno.getText();
        String TxtName = jTxtRegName.getText();
        String TxtFname = jTxtRegFname.getText();
        String TxtMobile = jTxtRegMobile.getText();
        String TxtEmail = jTxtRegEmail.getText();
        String RtbAddress = jRtbRegAddress.getText();
        String TxtUname = jTxtRegUname.getText();
        String PdPsd = new String(jPdRegPsd.getPassword());
        
        try
        {
          String sql="insert into registration (REGSLNO,REGNAME,REGFNAME,REGDOB,REGGENDER,
                     REGMATRIC,REGINTER,REGGRAD,REGPG,REGMOBILE,REGEMAIL,REGSTATE,REGADDRESS,
                     REGUNAME,REGPSD)values('"+TxtSlno+"','"+TxtName+"','"+TxtFname+"','"+pp+"',
                     '"+gender+"','"+ChkMatric+"','"+ChkInter+"','"+ChkGrad+"','"+ChkPg+"',
                     '"+TxtMobile+"','"+TxtEmail+"','"+CmbState1+"','"+RtbAddress+"',
                     '"+TxtUname+"','"+PdPsd+"')";
            st=conn.createStatement();
            st.executeUpdate(sql);
            //out.println("Data Saved Successfully..");
            showMessageDialog(null, "Data Saved Successfully..");
        }
        catch(Exception e)
        {
           System.out.println(e);
        }
   }
}

Example : How to Save/Store data or record in oracle 10g database (2nd Method).

// Write Java-Oracle 10g Connectivity Code here first properly/globally.
 
private void jBtnRegSubmitActionPerformed(java.awt.event.ActionEvent evt) 
{   
        //String TxtSlno = jTxtRegSlno.getText();
        
        String gender = " ";
        if(jRdbRegMale.isSelected())
          {
            gender="Male";
          }
        if(jRdbRegFemale.isSelected())
          {
            gender="Female";
          }
        if(jRdbRegOther.isSelected())
          {
            gender="Other";
          } 

   try
   {
            pst = conn.prepareStatement("insert into REGISTRATION values(?,?,?,?)"); 

            pst.setString(1,jTxtRegSlno.getText().toString());    //Code for java controls.
            pst.setString(2,jTxtRegName.getText().toString());
            pst.setString(3,jTxtRegFname.getText().toString());
            pst.setString(4,gender.toString());                   //Code for java variables.            


              |
              |     //Rest code is written here for other java controls 
              |

            
            int x = pst.executeUpdate();
            if(x!=0)
             {
                showMessageDialog(null,"Data saved Successfully....");
             }
    }
    catch(Exception e)
    {
            out.println(e);
    }
}

NB : During using this method of save code,all the table's fields/columns must be used or included in save code from column location 1,2,3,...(such as... values ?,?,?,? as mentioned above)   

Example : How to Save/Store data or record in oracle 10g database (3rd Method).

// Write Java-Oracle 10g Connectivity Code here first properly/globally.
 
private void jBtnRegSubmitActionPerformed(java.awt.event.ActionEvent evt) 
{   
        //String TxtFname = jTxtRegFname.getText();
        
        String gender = " ";
        if(jRdbRegMale.isSelected())
          {
            gender="Male";
          }
        if(jRdbRegFemale.isSelected())
          {
            gender="Female";
          }
        if(jRdbRegOther.isSelected())
          {
            gender="Other";
          } 

   try
   {
            String sql= "insert into ROUGHTABLE(SLNO,NAME)values(?,?)";
            pst=conn.prepareStatement(sql);
            
            pst.setString(1,jTxtRegSlno.getText().toString());    //Code for java controls.
            pst.setString(2,jTxtRegName.getText().toString());
            //pst.setString(3,TxtFname);
            //pst.setString(4,gender);                   //Code for java variables.            


              |
              |     //Rest code is written here for other java controls 
              |
            
             pst.addBatch();
             pst.executeBatch();
             showMessageDialog(null,"Data Saved Successfully");
    }
    catch(Exception e)
    {
            out.println(e);
    }
}

Loading

Categories: Java Project

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.