title: Java Jdbc SQL Exception (Syntax Error)
body: <p>I'm working a login sample for my Enrollment System. While doing some research grab some codes that I see on the internet. Which I will login in the fields of Username &amp; Password. Where I encounter error using SQL. Any help, tips will appreciate!</p>
  
  <p><strong>ERROR</strong></p>
  
  <pre><code>Error message: Syntax error: Encountered "," at line 1, column 42.
  Error code: -1
  SQL State: 42X01
  </code></pre>
  
  <p>This is where the compiler pointing the error at line 1, Column 42. I used Windows Listener for the which can I used for system closing.</p>
  
  <p><strong>Window Listener Code</strong> </p>
  
  <pre><code>//Window Listener
      addWindowListener(new WindowAdapter(){
         public void windowClosing(WindowEvent e){
             System.exit(0);
         }//window Closing
         });
  </code></pre>
  
  <p><strong>Code</strong> This is where I login. When I finish filling up the username and password textfields and hit the login button Which where I encounter the error.</p>
  
  <pre><code>loginButton.addActionListener(new ActionListener (){
       public void actionPerformed(ActionEvent e){
  
           String inputUsername = usernameTextField.getText().trim();
           String inputPassword = String.valueOf(passwordPasswordField.getText());
           String inputUserType = listUser.getSelectedItem().toString();
  
            if(inputUsername.isEmpty() &amp;&amp; inputPassword.isEmpty()){
                    JOptionPane.showMessageDialog(null, "Please fill up!");
            }
            else if(inputUsername.isEmpty()){
                   JOptionPane.showMessageDialog(null, "Please enter your username");
            }
            else if(inputPassword.isEmpty()){
                   JOptionPane.showMessageDialog(null, "Please enter your password");
            }
            else{
                  String myQuery = "SELECT * FROM USERTYPE WHERE USERNAME = ?, PASSWORD = ?";
  
            try(Connection myConnection = DBUtil.getConnection(DBType.JDBC);
                         PreparedStatement myPs = myConnection.prepareStatement(myQuery);
                         ResultSet myResultSet = myPs.executeQuery()){ 
  
                          while(myResultSet.next())
  
                              myPs.setString(1, inputUsername);
                              myPs.setString(2, inputPassword);
  
                              myPs.executeUpdate();
                              JOptionPane.showMessageDialog(null, "Succesfuly Inserted!");
                          //end of else
                      }//end of try   
  
                     catch(SQLException ex) {
                          DBUtil.processException(ex);
                      }//end of catch
                      }//end of else
          }//end of action performed
              });//end of action listener`
  </code></pre>
  
  <p><strong>DBUtil as my connection and exception</strong> This is where I set aside my connection and exception which where throws the error</p>
  
  <pre><code>private static final String dbUrl = "jdbc:derby://localhost:1527/Info";
  private static final String username = "john";
  private static final String pass = "john";
                                         //Argument for DBType
  public static Connection getConnection(DBType dbType) throws SQLException{
      return DriverManager.getConnection(dbUrl,username,pass);
  }
  
  public static void processException(SQLException e){
      System.err.println("Error message: "+e.getMessage());
      System.err.println("Error code: "+e.getErrorCode());
      System.err.println("SQL State: "+e.getSQLState());
  }
  </code></pre>