title: Error with connection: java.sql.SQLException: ORA-00917: missing comma
body: <p>I'm working on a Web Application using Java Servlets.  I am trying to implement login, logout, and registration functionality but I'm a little confused on how to get everything working.  Here is the code for the Login page:</p>
  
  <pre><code>To change this template, choose Tools | Templates
  * and open the template in the editor.
  */
  package hw5package;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.*;
  import java.util.UUID;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  /**
   *
   * @author Tyler
   */
  public class Login extends HttpServlet {
  
  /**
   * Processes requests for both HTTP
   * &lt;code&gt;GET&lt;/code&gt; and
   * &lt;code&gt;POST&lt;/code&gt; methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
      try {
          String driver = "oracle.jdbc.driver.OracleDriver";
          String url = "jdbc:oracle:thin:@cci-ora02.uncc.edu:1521:class";
          String username = "teverha4";
          String password = "qwe123";
  
          out.println("&lt;html&gt;");
          out.println("&lt;head&gt;");
          out.println("&lt;title&gt;ITIS 4166 Project&lt;/title&gt;");
          out.println("&lt;/head&gt;");
          out.println("&lt;body&gt;");
          out.println("&lt;div align='center'&gt;");
          out.println("&lt;h1&gt;ITIS 4166 Project - Login Page&lt;/h1&gt;");
          out.println("&lt;h2&gt;by: Tyler Everhart&lt;/h2&gt;");
  
          out.println("&lt;br /&gt;");
          out.println("&lt;br /&gt;");
          out.println("&lt;br /&gt;");
          out.println("&lt;br /&gt;");
  
          out.println("&lt;table width='20%' border='1' cellspacing='1' cellpadding='1'&gt;");
          out.println("&lt;form id='loginForm' name='loginForm' method='POST'&gt;");
          out.println("&lt;tr&gt;");
          out.println("&lt;td bgcolor='006F13' align='left' colspan='2'&gt;&lt;b&gt;Login&lt;/b&gt;&lt;/td&gt;");
          out.println("&lt;/tr&gt;");
  
          out.println("&lt;tr&gt;");
          out.println("&lt;td bgcolor='35D551' align='left'&gt;Username:&lt;/td&gt;");
          out.println("&lt;td bgcolor='35D551'&gt;");
          out.println("&lt;input type='text' name='username' id='username' /&gt;");
          out.println("&lt;/td&gt;");
          out.println("&lt;/tr&gt;");
          String passUsername = request.getParameter("username");
  
          out.println("&lt;tr&gt;");
          out.println("&lt;td bgcolor='35D551' align='left'&gt;Password:&lt;/td&gt;");
          out.println("&lt;td bgcolor='35D551'&gt;");
          out.println("&lt;input type='password' name='pwd' id='pwd' /&gt;");
          out.println("&lt;/td&gt;");
          out.println("&lt;/tr&gt;");
          String passPwd = request.getParameter("pwd");
  
          out.println("&lt;tr&gt;");
          out.println("&lt;td bgcolor='006F13' align='center' colspan='2'&gt;");
          out.println("&lt;input type='submit' value='Submit' onclick='loginValidation()' /&gt; ");
          out.println("&lt;input type='reset' value='Reset' /&gt;");
          out.println("&lt;/td&gt;");
          out.println("&lt;/tr&gt;");
          out.println("&lt;/form&gt;");
          out.println("&lt;/table&gt;");
          out.println("&lt;a href='Registration'&gt;New User, Click Here to Register&lt;/a&gt;");
          out.println("&lt;/div&gt;");
          out.println("&lt;/body&gt;");
          out.println("&lt;/html&gt;");
  
          Class.forName(driver);
  
          Connection connection = DriverManager.getConnection(url, username, password);
  
          Statement statement = connection.createStatement();
          String query = "SELECT UserName, PassWord FROM UserLogin";
  
          ResultSet resultSet = statement.executeQuery(query);
  
          HttpSession session = request.getSession(true);
  
          while (resultSet.next()) {
              if ((passUsername.equals(resultSet.getString("UserName")) &amp;&amp; passPwd.equals(resultSet.getString("PassWord")))) {
                  String sessionID = UUID.randomUUID().toString();
                  session.setAttribute("username", passUsername);
                  session.setAttribute("sessionID", sessionID);
                  response.sendRedirect("Categories");
              }
              else if (passUsername.equals("") || passPwd.equals("")) {
                  out.println("Enter a username and password.");
              }
              else {
                  out.println("Either your username or password is incorrect or could not be found.");
                  out.println("Please try again, or click the link below to register.");
              }
          }
      }
      catch (ClassNotFoundException cnfe) {
          System.err.println("Error loading driver: " + cnfe);
          out.println("&lt;tr&gt;Error loading driver: " + cnfe + "&lt;/tr&gt;");
      }
      catch (SQLException sqle) {
          System.err.println("Error with connection: " + sqle);
          out.println("&lt;tr&gt;Error with connection: " + sqle + "&lt;/tr&gt;");
      }
      finally {            
          out.close();
      }
  }
  
  // &lt;editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."&gt;
  /**
   * Handles the HTTP
   * &lt;code&gt;GET&lt;/code&gt; method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      processRequest(request, response);
  }
  
  /**
   * Handles the HTTP
   * &lt;code&gt;POST&lt;/code&gt; method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      processRequest(request, response);
  }
  
  /**
   * Returns a short description of the servlet.
   *
   * @return a String containing servlet description
   */
  @Override
  public String getServletInfo() {
      return "Short description";
  }// &lt;/editor-fold&gt;
  </code></pre>
  
  <p>}</p>
  
  <p>Here is the code for the Registration page:</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package hw5package;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.*;
  import java.util.Random;
  import java.util.UUID;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  /**
   *
   * @author Tyler
   */
  public class Registration extends HttpServlet {
  
  /**
   * Processes requests for both HTTP
   * &lt;code&gt;GET&lt;/code&gt; and
   * &lt;code&gt;POST&lt;/code&gt; methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
      try {
          String driver = "oracle.jdbc.driver.OracleDriver";
          String url = "jdbc:oracle:thin:@cci-ora02.uncc.edu:1521:class";
          String username = "teverha4";
          String password = "qwe123";
  
          out.println("&lt;html&gt;");
          out.println("&lt;head&gt;");
          out.println("&lt;title&gt;ITIS 4166 Project&lt;/title&gt;");
          out.println("&lt;/head&gt;");
          out.println("&lt;body&gt;");
          out.println("&lt;div align='center'&gt;");
          out.println("&lt;h1&gt;ITIS 4166 Project - Registration Page&lt;/h1&gt;");
          out.println("&lt;h2&gt;by: Tyler Everhart&lt;/h2&gt;");
  
          out.println("&lt;br /&gt;");
          out.println("&lt;br /&gt;");
          out.println("&lt;br /&gt;");
          out.println("&lt;br /&gt;");
  
          out.println("&lt;table width='25%' border='1' cellspacing='1' cellpadding='1'&gt;");
          out.println("&lt;tr&gt;");
          out.println("&lt;th bgcolor='006F13' align='left' colspan='2'&gt;Register Account Information&lt;/th&gt;");
          out.println("&lt;/tr&gt;");
  
          out.println("&lt;tr&gt;");
          out.println("&lt;td bgcolor='35D551' align='left'&gt;Requested Username:&lt;/td&gt;");
          out.println("&lt;td bgcolor='35D551'&gt;");
          out.println("&lt;form id='enterForm' name='enterForm'&gt;");
          out.println("&lt;input type='text' name='requested_username' /&gt;");
          out.println("&lt;/td&gt;");
          out.println("&lt;/tr&gt;");
          String passUsername = request.getParameter("requested_username");
  
          out.println("&lt;tr&gt;");
          out.println("&lt;td bgcolor='35D551' align='left'&gt;Password:&lt;/td&gt;");
          out.println("&lt;td bgcolor='35D551'&gt;");
          out.println("&lt;input type='password' name='pwd' /&gt;");
          out.println("&lt;/td&gt;");
          out.println("&lt;/tr&gt;");
          String passPwd = request.getParameter("pwd");
  
          out.println("&lt;tr&gt;");
          out.println("&lt;td bgcolor='35D551' align='left'&gt;Confirm Password:&lt;/td&gt;");
          out.println("&lt;td bgcolor='35D551'&gt;");
          out.println("&lt;input type='password' name='pwd1' /&gt;");
          out.println("&lt;/td&gt;");
          out.println("&lt;/tr&gt;");
          String passPwd1 = request.getParameter("pwd1");
  
          out.println("&lt;tr&gt;");
          out.println("&lt;td bgcolor='006F13' align='center' colspan='2'&gt;");
          out.println("&lt;input name='Submit' type='submit' value='Submit' /&gt; ");
          out.println("&lt;input type='reset' value='Reset' /&gt;");
          out.println("&lt;/td&gt;");
          out.println("&lt;/tr&gt;");
          out.println("&lt;/form&gt;");
          out.println("&lt;/table&gt;");
          out.println("&lt;/div&gt;");
          out.println("&lt;/body&gt;");
          out.println("&lt;/html&gt;");
  
          Class.forName(driver);
  
          Connection connection = DriverManager.getConnection(url, username, password);
  
          Statement statement = connection.createStatement();
  
          HttpSession session = request.getSession();
  
          if (passPwd.equals("") || passPwd1.equals("")) {
              Integer registerError = Integer.valueOf(1);
              session.setAttribute("registerError", registerError);
              out.println("Please enter a valid password.");
          }
          else if (!passPwd.equals(passPwd1)) {
              Integer registerError = Integer.valueOf(2);
              session.setAttribute("registerError", registerError);
              out.println("Your password and confirm password does not match.");
          }
          else {
              String query2 = "INSERT INTO UserLogin (UserName, PassWord, StockAmt, TechnologyStock, UtilityStock) VALUES (?,?,?,?,?)";
              PreparedStatement stmt = connection.prepareStatement(query2);
              stmt.setString(1, passUsername);
              stmt.setString(2, passPwd);
              stmt.setInt(3, 0);
              stmt.setInt(4, 0);
              stmt.setInt(5, 0);
              stmt.executeQuery();
              session.setAttribute("sessionUsername", passUsername);
              String sessionID = UUID.randomUUID().toString();
  
              Random StockID1 = new Random();
              StockID1.nextInt(10);
              String insertDataSqlMicrosoft = "INSERT INTO StockInfo(StockID, UserID, Type, StockName, Owned, Price, Total) VALUES('" + StockID1 + "','" + passUsername + ",'Technology','Microsoft (MSFT)',0,32.75,0";
              PreparedStatement stmtMicrosoft = connection.prepareStatement(insertDataSqlMicrosoft);
              stmtMicrosoft.executeQuery();
  
              Random StockID2 = new Random();
              StockID2.nextInt(4);
              String insertDataSqlIntel = "INSERT INTO StockInfo(StockID, UserID, Type, StockName, Owned, Price, Total) VALUES('" + StockID2 + "','" + passUsername + "','Technology','Intel (INTC)',0,26.75,0)";
              PreparedStatement stmtIntel = connection.prepareStatement(insertDataSqlIntel);
              stmtIntel.executeQuery();
  
              Random StockID3 = new Random();
              StockID3.nextInt(9);
              String insertDataSqlDuke = "INSERT INTO StockInfo(StockID, UserID, Type, StockName, Owned, Price, Total) VALUES('" + StockID3 + "','" + passUsername + "','Utility','Duke Energy (DUK)',0,89.00,0";
              PreparedStatement stmtDuke = connection.prepareStatement(insertDataSqlDuke);
              stmtDuke.executeQuery();
  
              Random StockID4 = new Random();
              StockID4.nextInt(7);
              String insertDataSqlCable = "INSERT INTO StockInfo(StockID, UserID, Type, StockName, Owned, Price, Total) VALUES('" + StockID4 + "','" + passUsername + "','Utility','Time Warner Cable (TWC)',0,30.00,0)";
              PreparedStatement stmtCable = connection.prepareStatement(insertDataSqlCable);
              stmtCable.executeQuery();
  
              session.setAttribute("sessionID", sessionID);
              response.sendRedirect("Categories");
          }
      } 
      catch (ClassNotFoundException cnfe) {
          System.err.println("Error loading driver: " + cnfe);
          out.println("&lt;tr&gt;Error loading driver: " + cnfe + "&lt;/tr&gt;");
      }
      catch (SQLException sqle) {
          System.err.println("Error with connection: " + sqle);
          out.println("&lt;tr&gt;Error with connection: " + sqle + "&lt;/tr&gt;");
      } finally {            
          out.close();
      }
  }
  
  // &lt;editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."&gt;
  /**
   * Handles the HTTP
   * &lt;code&gt;GET&lt;/code&gt; method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      processRequest(request, response);
  }
  
  /**
   * Handles the HTTP
   * &lt;code&gt;POST&lt;/code&gt; method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      processRequest(request, response);
  }
  
  /**
   * Returns a short description of the servlet.
   *
   * @return a String containing servlet description
   */
  @Override
  public String getServletInfo() {
      return "Short description";
  }// &lt;/editor-fold&gt;
  }
  </code></pre>
  
  <p>I figured out the problem that I was having before with reading from the database only to now have a new problem.  When I type in a username and password that I have verified are present in the database I am not redirected to the page that I want to go to.  Also when I try to register a new user I am not redirected to the page and am given an error that says:</p>
  
  <p>Error with connection: java.sql.SQLException: ORA-00917: missing comma </p>
  
  <p>The username and password for the person registering are sent to the database but the program doesn't redirect you to the appropriate page.</p>