title: java - return array from method
body: <p>I created this snippet:</p>
  
  <pre><code>public static String[] get_data()
  {
      conn = getInstance();
      String[] data_array = null;
      if(conn != null)
      {
          Statement query;
          try 
          {
              query = conn.createStatement();
  
              String sql = "SELECT data_x FROM table_x";
              ResultSet result = query.executeQuery(sql);
  
              result.next();
              int count = result.getInt("data_x");
              result.close();
  
              data_x_array = new String[count];
  
              for (int x = 1; x &lt;= count; x++)
              {
                  String data_x = result.getString(x);
                  data_x_array[x] = data_x;
              }
          } 
          catch (SQLException e) 
          {
              e.printStackTrace();
          }
      }
      return data_x_array;
  }
  </code></pre>
  
  <p>I just created a class, where data from the database is collected in an array.</p>
  
  <p>Now i just want to return the array from this method.</p>
  
  <p>But what i get is:</p>
  
  <pre><code>data_array cannot be resolved to a variable
  </code></pre>
  
  <p>Anybody could help me ?</p>
  
  <p>Greetings!</p>
  
  <p>UPDATE:</p>
  
  <p>i changed snippet to:</p>
  
  <pre><code>public static String[] get_data()
  {
      conn = getInstance();
      String[] data_array = null;
      if(conn != null)
      {
          Statement query;
          try 
          {
              query = conn.createStatement();
  
              String sql = "SELECT data_x FROM table_x";
              ResultSet result = query.executeQuery(sql);
  
              result.next();
              int count = result.getInt("data_x");
              result.close();
  
              data_array = new String[count];
  
              for (int x = 1; x &lt;= count; x++)
              {
                  String data_x = result.getString(x);
                  data_x_array[x] = data_x;
              }
          } 
          catch (SQLException e) 
          {
              e.printStackTrace();
          }
      }
      return data_x_array;
  }
  </code></pre>
  
  <p>When i compile just:</p>
  
  <pre><code>Invalid value for getInt() - 'value_in_table'
  </code></pre>
  
  <p>Anybody know this?</p>
  
  <p>Greetings!</p>