title: Compilation Error When Trying to Write a Servlet to Insert HTML Form Data into a Database
body: <p>I'm getting a minor compilation error trying to write a servlet and I've checked all the {} and ;</p>
  
  <p>Here is the code: </p>
  
  <pre><code>//This servlet processes the user's registration and redirects them to the catalog.
  
  // Load required libraries
  import java.io.*;
  import java.util.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.sql.*;
  
  public class DatabaseAccess extends HttpServlet{
  
  // JDBC driver name and database URL
  private static final String JDBC_DRIVER="com.mysql.jdbc.Driver";  
  private static final String DB_URL="jdbc:mysql://localhost/dvdsite";
  
  public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
              throws ServletException, IOException
  
        //  Database credentials
        static final String USER = "user";
        static final String PASS = "";
  
        // Get form values from register page
        String username = request.getParameter("username");
        int userID = Integer.parseInt(username);
        String password = request.getParameter("password");
        String email = request.getParameter("email");
  {
        try {
           // Register JDBC driver
           Class.forName("com.mysql.jdbc.Driver");
  
           // Open a connection
           conn = DriverManager.getConnection(DB_URL,USER,PASS);
  
           // Execute SQL query
           stmt = conn.createStatement();
           String sql;
           sql = "INSERT INTO dvdsite values (username, password, email)";
           ResultSet rs = stmt.executeQuery(sql);
  
           // Clean-up environment
           rs.close();
           stmt.close();
           conn.close();
        }catch(SQLException se){
           //Handle errors for JDBC
           se.printStackTrace();
        }catch(Exception e){
           //Handle errors for Class.forName
           e.printStackTrace();
        }finally{
           //finally block used to close resources
           try{
              if(stmt!=null)
                 stmt.close();
           }catch(SQLException se2){
           }// nothing we can do
           try{
              if(conn!=null)
              conn.close();
           }catch(SQLException se){
              se.printStackTrace();
           }//end finally try
        } //end try
     }
  } 
  </code></pre>
  
  <p>Here is the error I'm getting: 1 error found:
  File: /Applications/MAMP/htdocs/register.java  [line: 18]
  Error: /Applications/MAMP/htdocs/register.java:18: ';' expected</p>
  
  <p>The errors comes up on this line:</p>
  
  <p>throws ServletException, IOException</p>
  
  <p>Can anyone help?</p>