title: How to assign NULL value to a string and then insert it in mysql database
body: <p>Here I'am calculating the average of one column
  If the avg comes to be 0.0, then i would want to assign the string variable as <code>NULL</code> else the avg value itself.</p>
  
  <p>These values are getting stored in mysql db
  Now my problem is that when the avg does come 0.0, string  NULL gets stored but i want the default NULL value to get stored in it.</p>
  
  <p>How can i assign NULL (and not string NULL) to variable ans??</p>
  
  <pre><code>private void btnAdd1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
      // TODO add your handling code here:
       Connection conn = null;
              Statement st = null;          
              ResultSet rs = null;
  
          try{
  
    conn = DriverManager.getConnection("jdbc:mysql://localhost/check","root","");
      st = conn.createStatement();
  
      String sql4 =("SELECT AVG(unit4) as num FROM lo where unit4 IS NOT NULL");
           PreparedStatement pstmt3 = conn.prepareStatement(sql4);
           ResultSet rs4 = pstmt3.executeQuery();
       rs4.next();
       double a3 = rs4.getDouble("num");
       double b3 = Math.round(a3*10);
       double res5 = b3/10;
       rs4.next();
       avg1.setText(String.valueOf(res5));
       String a1 =avg1.getText();
       String ans ;
  
      if(a1.equals("0.0")){
          ans = null;
      }else{
          ans = a1;
      }
  
      String query = "INSERT INTO chk(id) VALUES ('"+ans+"')";
      executeSQlQuery(query, "Inserted");
  
      }   
  </code></pre>