0

i have used the following code(addAStudent and login methods )to perform Register and login operation for a simple Student Management System. I can able to execute the addAStudent method without any issues, but i am unable to execute the login method

@Override
    public void addAStudent(String firstName, String lastName, String middleName, String username, String password, String emailId)
    {
       JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource);
       jdbcTemplate.update("insert into Student(email_id,first_name,last_name,middle_name,password,username) values(?,?,?,?,?,?)",emailId,firstName,lastName,middleName,password,username);
    }
    @Override
    public void login(String username,String password)
    {
        
        JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource);
        jdbcTemplate.query("select * from student_info where uname=? and password=?",username,password);
        
    }

please tell me, what is my mistake

Screenshot

4
  • Any exceptoins? Does the student_info have uname and password columns? Commented Jul 26, 2018 at 18:18
  • It's hard to help you without 1) your spring config 2) error/exception logs. Commented Jul 26, 2018 at 18:18
  • The modified code is JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource); jdbcTemplate.query("select * from student where username=? and password=?",username,password); Commented Jul 26, 2018 at 18:27
  • give your stack trace && Student class Commented Jul 26, 2018 at 18:49

1 Answer 1

1

If yuo use java 8 then select like:

jdbcTemplate.query("SELECT s.username as c1, s.password as c2 from student s where s.username = ? and s.password = ?",
            new Object[]{username,password}),
            (rs ->{
                Student student = new Student();
                student.username = rs.getString("c1");
                student.passwrod = rs.getString("c2");
                return student;
            });

i think your table name student.

       jdbcTemplate.update("insert into student(email_id,first_name,last_name,middle_name,password,username) values(?,?,?,?,?,?)",emailId,firstName,lastName,middleName,password,username);
Sign up to request clarification or add additional context in comments.

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.