0

I'm currently new to JAVAfx and I am trying to create a signup user method. When I run the program I get this error:


java.sql.SQLException: No value specified for parameter 2
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:130)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:379)
    at com.example.demo2/com.example.demo2.DatabaseHandler.signUpUser(DatabaseHandler.java:34)
    at com.example.demo2/com.example.demo2.registerController.lambda$initialize$0(registerController.java:37)

    public void signUpUser(String firstName, String lastName, String email, String password) {

        String insert = "INSERT INTO " + Const.USERS_TABLE + "(" + Const.USERS_FIRSTNAME + "," + "VALUES(????)";

        try {
            PreparedStatement preparedStatement = getDbConnection().prepareStatement(insert);

            preparedStatement.setString(1,firstName);
            preparedStatement.setString(1,lastName);
            preparedStatement.setString(1,email);
            preparedStatement.setString(1,password);

            preparedStatement.execute();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }

Any help would be great. I think this method is faulty.

Thanks

sqlcoder
  • 27
  • 8
  • The error is telling you exactly what is wrong as you appear to be assigning all SQL variables to the same parameter, parameter 1. – Hovercraft Full Of Eels Jul 15 '23 at 19:03
  • Thanks I have just noticed. I changed the parameters and it has produced another error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES('q''a''a''ss')' at line 1 – sqlcoder Jul 15 '23 at 19:06
  • Shouldn't there be commas? – Hovercraft Full Of Eels Jul 15 '23 at 19:08
  • Have you gone through the relevant tutorials on this topic? You can find some resources both [here](https://stackoverflow.com/tags/sql/info) and [here](https://stackoverflow.com/tags/mysql/info) – Hovercraft Full Of Eels Jul 15 '23 at 19:08
  • yes I am getting really confused. I am very new to this, so I could be making stupid mistakes. – sqlcoder Jul 15 '23 at 19:10
  • @HovercraftFullOfEels managed to solve the issue it was the commas lol. These small mistakes stress you out!! thanks for the advice and your time (: – sqlcoder Jul 15 '23 at 19:35

0 Answers0