Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. 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

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

Scheduled Pinned Locked Moved Database
databasetutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LOKENDRA YADAV
    wrote on last edited by
    #1

    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); }

    Richard DeemingR 1 Reply Last reply
    0
    • L LOKENDRA YADAV

      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); }

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      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

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups