how to rertrieve only 3 columns out of 7 columns using queryForObject in jDBCTmplate????am unable use correct syntax to retrieve only 3 columns in JdbcStudentDAO
-
What I am tring to do is to select the username, password, and role from studentstable using queryForObject. In my JdbcTemplate syntax is --------------Public static Object queryForObject(String sql,RowMAPPER mapper,Object ...args)----------------
public class JdbcStudentDAO implements StudentDAO{ public String getLogin(StudentTO sto) { String sql="select username,password,role from studentstable"; System.out.println(sql); -----------------------------Below has something wrong with queryForObject----------------------------------------------------------- Object obj=JdbcTemplate.queryForObject(sql,new StudentRowMapper(),sto.getUsername(),sto.getPassword(),sto.getRole()); StudentTO sto1=(StudentTO)obj; System.out.println(sto1); return sto1.toString(); } }
-------------------------This is my RowMapper where I'm getting all rows of my database, as shown below-------------------- public class StudentRowMapper implements RowMapper{ public Object mapRow(ResultSet rs) throws SQLException { StudentTO sto=new StudentTO(); sto.setSid(rs.getInt(1)); sto.setName(rs.getString(2)); sto.setUsername(rs.getString(3)); sto.setPassword(rs.getString(4)); sto.setEmail(rs.getString(5)); sto.setPhone(rs.getLong(6)); sto.setRole(rs.getString(7)); return sto; } } -----------------------------------This is an abstract method in StudentDAO--------------------------- public interface StudentDAO { public String getLogin(StudentTO sto); } -
What I am tring to do is to select the username, password, and role from studentstable using queryForObject. In my JdbcTemplate syntax is --------------Public static Object queryForObject(String sql,RowMAPPER mapper,Object ...args)----------------
public class JdbcStudentDAO implements StudentDAO{ public String getLogin(StudentTO sto) { String sql="select username,password,role from studentstable"; System.out.println(sql); -----------------------------Below has something wrong with queryForObject----------------------------------------------------------- Object obj=JdbcTemplate.queryForObject(sql,new StudentRowMapper(),sto.getUsername(),sto.getPassword(),sto.getRole()); StudentTO sto1=(StudentTO)obj; System.out.println(sto1); return sto1.toString(); } }
-------------------------This is my RowMapper where I'm getting all rows of my database, as shown below-------------------- public class StudentRowMapper implements RowMapper{ public Object mapRow(ResultSet rs) throws SQLException { StudentTO sto=new StudentTO(); sto.setSid(rs.getInt(1)); sto.setName(rs.getString(2)); sto.setUsername(rs.getString(3)); sto.setPassword(rs.getString(4)); sto.setEmail(rs.getString(5)); sto.setPhone(rs.getLong(6)); sto.setRole(rs.getString(7)); return sto; } } -----------------------------------This is an abstract method in StudentDAO--------------------------- public interface StudentDAO { public String getLogin(StudentTO sto); }LOKENDRA YADAV wrote:
select username,password,role from studentstable
Not an answer to your question, but there's a more fundamental problem with your code: You're storing passwords in plain text. NEVER do that. And don't use reversible encryption either. Store a salted hash of the password, using a unique salt per record. Secure Password Authentication Explained Simply[^] Salted Password Hashing - Doing it Right[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer