title: JEE Servlet SQLException practice
body: <p>Is it good practice to handle exception like this? Or there is any better alternative way to do it?
  The code works fine but I feel that not all the Exceptions of getAllGrades() method will be shown because of throws added infront of connection().
  Please correct me if I'm wrong.</p>
  <pre><code>package DAO;
  
  import java.sql.*;
  import java.util.ArrayList;
  
  public class StudentDAO {
      static Connection con;
      static PreparedStatement stmt;
      static ResultSet rs;
      public static void connection() throws Exception {
          Class.forName(&quot;oracle.jdbc.driver.OracleDriver&quot;);
          con = DriverManager.getConnection(&quot;jdbc:oracle:thin:@localhost:1521:xe&quot;, &quot;xxx&quot;, &quot;yyy&quot;);
      }
      public static ArrayList&lt;String&gt; getAllGrades() {
          try {
              connection();
              stmt=con.prepareStatement(&quot;SELECT DISTINCT grade from student&quot;);
              rs=stmt.executeQuery();
              ArrayList&lt;String&gt; grades=new ArrayList&lt;String&gt;();
              while(rs.next()) {
                  grades.add(rs.getString(1));
              }
              con.close();
              return grades;
          }
          catch(SQLException e) {
              e.printStackTrace();
          } catch (Exception e) {
              e.printStackTrace();
          }
          return null;        
      }
  }
  </code></pre>