title: SQL queries in Java: (JDBC) How to use the SELECT statement?
body: <p><a href="http://i.stack.imgur.com/YgaAC.png" rel="nofollow">MysqlDatabase</a></p>
  
  <p>This is my query to connect to my database.</p>
  
  <pre><code>SELECT naam, kleur, sector, aantalZilverstukken, Spel_naam 
  FROM speler 
  WHERE Spel_Naam = ?
  </code></pre>
  
  <p>I work in the console of netbeans. When I want to show the records of table Speler with the Spel_Naam. </p>
  
  <p>In the console I want to type a primary key of the table Spel and then it shows me the records of the table Speler in the console. How can I do this. </p>
  
  <p>Like <code>WHERE Spel_Naam = ?</code></p>
  
  <p>The question mark need to be the name that I typed in</p>
  
  <p>Is the select statement correct? I want to type the Spel_Naam in the console and then It must connect to the database and give me the records of table Speler. How can I do this?</p>
  
  <pre><code>public class SpelerMapper
  {
      private final static String LEES_SPELERS_SQL = "SELECT naam, kleur, sector, aantalZilverstukken, Spel_naam FROM speler WHERE Spel_Naam = ?";
  
      public List&lt;Speler&gt; geefSpelers()
      {
  
          List&lt;Speler&gt; spelerLijst = new ArrayList&lt;Speler&gt;();
  
          Statement statement;
          Connection connection = PersistentieController.getInstance().getConnection();
          try
          {
              statement = connection.createStatement();
  
              // query database
              ResultSet resultSet = statement.executeQuery(LEES_SPELERS_SQL);
  
              while (resultSet.next())
              {
  
                  String naam = resultSet.getString("naam");
                  String kleur = resultSet.getString("kleur");
                  int sector = resultSet.getInt("sector");
                  int aantalZilverstukken = resultSet.getInt("aantalZilverstukken");
  
                  Speler speler = new Speler(naam ,kleur, sector , aantalZilverstukken);
                  spelerLijst.add(speler);
              }
              statement.close();
              return spelerLijst;
          } catch (SQLException e)
          {
              e.printStackTrace();
          }
  
      return null;
  
  }
  </code></pre>