title: anything wrong with passing these variables in java
body: <p>Ambitious newbie here. Help wanted please.</p>
  
  <p>On trying to connect to a MySQL database and show results to a <code>JTable</code>, my query accepts parameters from some variables thus:</p>
  
  <pre><code>private String conv = "c_name as name,gender";
  private String varYear;
  
  [later when a JButton makes a click action, it tries to connect and display the results]
  
   try{
      varYear = yearTF.getText();
  
      //troubleshooting my varYear variable with this next dialog shows that the varYear variable gets the appropriate text that is entered into the yearTF textfield 
  
      JOptionPane.showMessageDialog(null, varYear);
  
      String sql = "SELECT  "+conv+" FROM  pTable WHERE  date LIKE  '%"+varMonth+"%' AND  date LIKE  '%"+varYear+"%' ";
  
      //now troubleshooting my statement with this next dialog shows that the varYear variable is null 
  
      JOptionPane.showMessageDialog(null, sql);
  
  
      pst = conn.prepareStatement(sql);
      rs = pst.executeQuery();
      Table_stats.setModel(DbUtils.resultSetToTableModel(rs));
  }catch(Exception e){
      JOptionPane.showMessageDialog(null, e);
  }
  </code></pre>
  
  <p>Question 1: What did the 'String sql = ...' do to the varYear that was first of all 2014 (for example) to become null?</p>
  
  <p>Question 2: How can I have my varYear to contain 2014 and not the null it has become?</p>
  
  <p>// varMonth suffers the same problem but I just asked for varYear hoping it'll shoot the two birds.
  Thanks.</p>