wood burning stoves 2.0*
The moose likes JDBC and the fly likes resultset value in vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "resultset value in vector" Watch "resultset value in vector" New topic
Author

resultset value in vector

Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
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

Joined: Jan 01, 2009
Posts: 874




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

Joined: Apr 05, 2008
Posts: 150

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!!! >


[Vipassana] - It is seeing the reality as it is, And not as you want it to be.!!!
SCJP1.5.
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684


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.





Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: resultset value in vector
 
Similar Threads
value from servlet to dropdown in jsp
Value in dropdown from servlet
update record for selection of id
assert method..
not getting value in doget method of servlet