0

i am curently getting this error:

java.sql.SQLSyntaxErrorException: 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 'FROMusersWHERElogin='Pac1man' ANDpassword='220v'' at line 1

What i need to do to fix it?

Here is my query:

public void SignUpUser(User user){
        String insert = "INSERT INTO " + Const.USER_TABLE + "(" + Const.USER_NAME + ","
                + Const.USER_SECONDNAME + "," + Const.USER_LOGIN + "," + Const.USER_PASSWORD + ")"
                + "VALUES(?,?,?,?)";
        try {

            PreparedStatement prSt = getDbConnection().prepareStatement(insert);
            prSt.setString(1, user.getName());
            prSt.setString(2, user.getSecondName());
            prSt.setString(3, user.getUserName());
            prSt.setString(4, user.getPasswordName());

            prSt.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public ResultSet getUser(User user){
        ResultSet resSet = null;

        String select = "SELECT * FROM" + Const.USER_TABLE + "WHERE" +
                Const.USER_LOGIN + "=? AND" + Const.USER_PASSWORD + "=?";

        try {
            PreparedStatement prSt = getDbConnection().prepareStatement(select);
            prSt.setString(1, user.getUserName());
            prSt.setString(2, user.getPasswordName());

            resSet = prSt.executeQuery();
        }   catch (SQLException e) {
            e.printStackTrace();
        }   catch (ClassNotFoundException e){
            e.printStackTrace();
    }
    return resSet;
}}

Any points?

2 Answers 2

1

You have a mistake (missing spaces) in the select variable.. Try this:

String select = "SELECT * FROM " + Const.USER_TABLE + " WHERE " +
                Const.USER_LOGIN + "=? AND " + Const.USER_PASSWORD + "=?";
Sign up to request clarification or add additional context in comments.

1 Comment

I love you :* Thanks bro
0

Your query is not valid because you missed to append space.

String select = "SELECT * FROM " + Const.USER_TABLE + " WHERE " +
                Const.USER_LOGIN + "=? AND " + Const.USER_PASSWORD + "=?";

Using above code now your query string is become

 SELECT * FROM users WHERE login='Pac1man' AND password='220v'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.