title: Why am I getting unhandled SQL Exception at rDao.insert(log)?
body: <p>Whenever I try to call insert method which is in RegisterDao I get an &quot;unhandled SQL exception&quot; error in Eclipse that forces me to add a catch try block. This always screws me up from there, because a try catch makes me initialize result as null... I can't get it to work.</p>
  <p>LogServlet.java</p>
  <pre><code>import java.io.IOException;
  import java.sql.SQLException;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  
  @WebServlet(&quot;/LogServlet&quot;)
  public class LogServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
         
      /**
       * @see HttpServlet#HttpServlet()
       */
      public LogServlet() {
          super();
          // TODO Auto-generated constructor stub
      }
  
       @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
          response.getWriter().append(&quot;Served at: &quot;).append(request.getContextPath());
          
       }
  
  
  @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      
           
              String id = request.getParameter(&quot;id&quot;);
              String name = request.getParameter(&quot;name&quot;);
              String title = request.getParameter(&quot;title&quot;);
              String date = request.getParameter(&quot;date&quot;);
              Log log = new Log(id, name, title, date);
          
              RegisterDao rDao = new RegisterDao();
           String result;
          result = rDao.insert(log);
          response.getWriter().print(result);
  }
  }
  
  </code></pre>
  <p>RegisterDao.java</p>
  <pre><code>import java.sql.Connection;
  import java.sql.Driver;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.SQLException;
  
  public class RegisterDao {
      
  
      private static final String USERNAME = &quot;dbuser&quot;;
      private static final String PASSWORD = &quot;dbpassword&quot;;
      private static final String M_CONN_STRING =
              &quot;jdbc:mysql://localhost/loggy&quot;;
  
      
      
      
      public String insert(Log log) throws SQLException {
      
      
          Connection con = DBUtil.getConnection(DBType.MYSQL);
          String result = &quot;Data entered successfully&quot;;
          String sql = &quot;insert into logs values(?,?,?,?)&quot;;
      
          PreparedStatement ps;
          try {
          ps = con.prepareStatement(sql);
          ps.setString(1, log.getid());
          ps.setString(2, log.getName());
          ps.setString(3, log.getTitle());
          ps.setString(4, log.getDate());
          ps.executeUpdate();
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              result = &quot;Data not entered&quot;;
          }
          return result;
      }
  
  }
  </code></pre>