title: How to insert values from different classes in the same table in MySQL using Java
body: <p>I have different values in different classes. I need to insert them in the same table. For example, by trying the example in this tutorial here: <a href="http://www.vogella.com/articles/MySQLJava/article.html" rel="nofollow">http://www.vogella.com/articles/MySQLJava/article.html</a></p>
  
  <p>If I have such code (assuming the DB connection successfully done in another class):</p>
  
  <pre><code>// PreparedStatements can use variables and are more efficient
      preparedStatement = connect.prepareStatement("insert into  FEEDBACK.COMMENTS
                           values (default, ?, ?, ?, ? , ?, ?)");
              // "myuser, webpage, datum, summery, COMMENTS from FEEDBACK.COMMENTS");
              // Parameters start with 1
              preparedStatement.setString(1, "Test");
              preparedStatement.setString(2, "TestEmail");
              preparedStatement.setString(3, "TestWebpage");
              preparedStatement.setDate(4, new java.sql.Date(2009, 12, 11));
              preparedStatement.setString(5, "TestSummary");
              preparedStatement.setString(6, "TestComment");
              preparedStatement.executeUpdate();
  </code></pre>
  
  <p>Assume that in one class I want to insert value 1, in the second class, I want to insert value 2, etc. By the end of my program, in the main function, I want to execute the update. Note that I wrote the:</p>
  
  <pre><code>preparedStatement = connect.prepareStatement("insert into  FEEDBACK.COMMENTS 
                      values (default, ?, ?, ?, ? , ?, ?)");
  </code></pre>
  
  <p>is in the main function. I have tried to define preparedStatement as public variable in the class that contains the main function, and if, for example, I need to insert value 2 in another class, I type: </p>
  
  <pre><code>preparedStatement.setString(2, "TestEmail");
  </code></pre>
  
  <p>but this results in error in the main function says: No value specified for parameter 2. So, <strong>how can I insert values from different classes in one table ??</strong></p>