I have a problem, I created a connection to an Oracle database using the JDBC driver.
All the examples I find on internet use like:
@SpringBootApplication
public class CanalCorSdqsApplication implements CommandLineRunner{
public static void main(String[] args) throws Exception {
SpringApplication.run(CanalCorSdqsApplication.class, args);
}
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public void run(String... args) throws Exception {
String sql = "SELECT * FROM USUARIO_WEBSERVICES";
List<UsuarioWebService> students = jdbcTemplate.query(sql,BeanPropertyRowMapper.newInstance(UsuarioWebService.class));
students.forEach(System.out :: println);
System.out.println(students.get(0).getLoginUsuario());
}
That works for me too, but when I try to do the same in another class, it throws
java.lang.NullPointerException:
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
public class ProcesoPrincipal implements CommandLineRunner {
@Autowired
private JdbcTemplate jdbcTemplate;
public void consulta(){
String sql = "SELECT * FROM USUARIO_WEBSERVICES";
List<UsuarioWebService> students = jdbcTemplate.query(sql,BeanPropertyRowMapper.newInstance(UsuarioWebService.class));
students.forEach(System.out :: println);
}
@Override
public void run(String... args) throws Exception {
String sql = "SELECT * FROM USUARIO_WEBSERVICES";
List<UsuarioWebService> students = jdbcTemplate.query(sql,BeanPropertyRowMapper.newInstance(UsuarioWebService.class));
students.forEach(System.out :: println);
}
In both methods it throws java.lang.NullPointerException.
Do you know what it is happening and how to fix?
this is the project: