title: How to fix "unreported exception InstantiationException; must be caught or declared to be thrown"
body: <p>I am building a simple HelloWorld application in NetBeans 8.1.
  It has to work simple wherein as soon as it will compile and run it will load all the data of a table acc in the database accounts using MySQL.</p>
  
  <p>I have included the Connector/J jar file in my project library and made a connection to MySQL but the Class.forName(com.mysql.jdbc.Driver).newInstance(); line in piece of code is showing "unreported exception InstantiationException; must be caught or declared to be thrown" and I exactly don't know what to do. I am kind of stuck here.</p>
  
  <p>Here's my code</p>
  
  <pre><code>package learning_jdbc;
  
  import java.sql.*;
  
  public class Hello {
      Connection connection;
      private void displaySQLErrors(SQLException e) {
          System.out.println("SQLException: " + e.getMessage());
          System.out.println("SQLState: " + e.getSQLState());
          System.out.println("VendorError: " + e.getErrorCode());
      }
  
      public Hello() {
          try {
              Class.forName("com.mysql.jdbc.Driver").newInstance();
          } catch (ClassNotFoundException e) {
              System.out.println("Class not found.");
          }
      }
  
      public void connectToDB() {
          try {
              connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/accounts","root","thejoker");
          } catch(SQLException e) {
              displaySQLErrors(e);
          }
      }
  
      public void executeSQL() {
          try (Statement statement = connection.createStatement();
                      ResultSet rs = statement.executeQuery("SELECT * FROM acc")) {
              while (rs.next()) {
                  System.out.println(rs.getString(1));
              }
              connection.close();
          } catch(SQLException e) {
              displaySQLErrors(e);
          }
      }
  
      public static void main(String[] args) {
          Hello hello = new Hello();
          hello.connectToDB();
          hello.executeSQL();
      }
  
  }
  </code></pre>