I have this series of code that takes data from database and then mapping it to a class.
The class is as follows (I didn't put the getter/setter to save space. Pretend that we already added the getter/setter).
public class MyClass{
private int id;
private String className;
private String classGroup;
}
And how I call my query is like this:
public MyClass getMyClass(String cn, String cg){
String query = "Select className, classGroup from MyClass where className = :className AND classGroup = :classGroup AND RowNum = 1"; //Imagine we're using Oracle SQL. If we use SQL Server/MySQL, then just replace AND RowNum = 1' with 'LIMIT 1'
return jdbcTemplate.query(query, newObject[]{cn,cg}, this::mapRow);
}
public MyClass mapRow (ResultSet rs, int i) throws SQLException{
MyClass mc = new MyClass();
mc.setClassName(rs.getString("className"));
mc.setClassGroup(rs.getString("groupName"));
return mc;
}
In general, it works. However, the jdbcTemplate.query command is deprecated. I do not know what's the alternative for scenarios like this: multiple variable within the query, returning a class/entity, sends the ResultSet to a function. So, can anyone help with the replacement for this so it's no longer deprecated?