title: Java: how to print the rows from database?
body: <p>I have this program:</p>
  
  <pre><code>class DataRetrieve {
  
      DataRetrieve() {
          try {
              Class.forName("com.mysql.jdbc.Driver");
              Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/phonebook", "root", "1234");
              Statement st = con.createStatement();
              st.executeQuery("select * from contacts");
          }
          catch(Exception e) {
              e.printStackTrace();
          }
      }
  }
  
  public class MainProgram {
  
      public static void main(String[] args) {
          DataRetrieve dr = new DataRetrieve();
          //here i want to print that table rows into Console using this
          System.out.println(); // How do you print here that table rows?
      }
  } 
  </code></pre>
  
  <p>Can anyone explain how to print this database information in <code>System.out.println</code>?</p>