Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

resultset value in vector

 
Nitin Belaram
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using vector to get result set value, but i am getting all 1st column value ,i am not getting all rows and column

[code]

public static List<New_USER> list() throws DaoException, ClassNotFoundException
{
System.out.println("inside list");
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
Vector listOfemp = new Vector();
// List<New_USER> users = new ArrayList<New_USER>();

try{
System.out.println("1");
connection = connectsql.getConnection();
System.out.println("2");
preparedStatement = connection.prepareStatement(SQL_FIND_BY_ID);
System.out.println(SQL_FIND_BY_ID);
resultSet = preparedStatement.executeQuery();
System.out.println(resultSet + "list Method");
while (resultSet.next()) {
listOfemp.addElement(resultSet.getString(1));

// users.add( mapNew_USER(resultSet));

System.out.println("After New_USER");
}
System.out.println(listOfemp +"AN");
}
catch (SQLException e) {
throw new DaoException(e);

}
return listOfemp;
}


please suggest how to get all value in result set
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



you can use resultSet.getString or Int(2)..(3) and so on till the no of columns requested in SELECT query.
resultSet.next() will fetch you all rows matching the Criteria in the SELECT query.

BTW you can run the generated query in the DB and check the output.
 
Pravin Shirke
Ranch Hand
Posts: 152
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nitin,
what you can do is:
Instead of this


insert this:


get all the columns like this or instead put a for loop inside a while loop



Hope this Helps!!! >
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

when you write


when you fire your query it gives result and it gives to your resultSet.

so you use resultSet.next iterate all row get by your query.



this gives you only first column of your resultSet.

you have to add all your column to your vector.




 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic