0

I wanted to retrieve the data stored in resultSet through the column names and the index of the row. Is there any way to do that? I tried through arraylist but I was not able to do that.

Example: There is table called Employee which has around 20 records with several columns such as ID, Name, Account, Project, Shift and Role. I want to access the data from the column 'Name' and 'Role' from the 5th row of resultSet i.e., something like (Name, 5) and (Row, 5). The column name will be taken from the user input. So I want to retrieve the data through column name. Is there any way to do that?

1 Answer 1

1

Interface java.sql.ResultSet has a collection of getter functions. The pattern is

getXxx(int columnIndex) getXxx(String columnLabel) 

Where Xxx is the data type to be fetched. The second variant fetches a value using the column header label.

To adust the cursor to a specific row, the function is

absolute(int rownum) 

If the call returns false it means there are no rows at that number. Caveat, not all drivers and queries allow navigation to any row number like that.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer.I assume by this way whole column will retrieve. But u need the record from a particular row using column name. For example (Name, 5) where Name is the column name and 5 is the index of the row.
@ManjunathChinnanagoudar If you need row 5, then just add a WHERE clause to your SQL statement.
It's just an example. I want to retrieve the value based on column name and row number.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.