appointments-software / src / main / java / odera / projects / appointmentssoftware / services / UserService.java
UserService.java
Raw
package odera.projects.appointmentssoftware.services;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.Map;

@Service
public class UserService {
    @Autowired
    JdbcTemplate jdbcTemplate;

    public Long getUserId(String username, String password) {
        String query = "SELECT * FROM appcentral.user where username=\""+username+"\" AND password=\""+password+"\"";
        Map<String, Object> result = jdbcTemplate.queryForMap(query);
        if (result.isEmpty()) {
            return -1L;
        } else return (Long)result.get("user_id");
    }
}