INTERVIEW QUESTIONS
J2EE
JDBC
DETAILS
Question: How can you retrieve data from the ResultSet?
Answer: First JDBC returns results in a ResultSet object, so we need to declare an instance of the class ResultSet to hold our results.
The following code demonstrates declaring the ResultSet object rs:-
E.g.
ResultSet rs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");
Second: String s = rs.getString("COF_NAME");
The method getString is invoked on the ResultSet object rs , so getString will retrieve (get) the value stored in the column COF_NAME in the current row of rs.
|
Question:
How can you retrieve data from the ResultSet?
Answer:
First JDBC returns results in a ResultSet object, so we need to declare an instance of the class ResultSet to hold our results.
The following code demonstrates declaring the ResultSet object rs:-
E.g.
ResultSet rs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");
Second: String s = rs.getString("COF_NAME");
The method getString is invoked on the ResultSet object rs , so getString will retrieve (get) the value stored in the column COF_NAME in the current row of rs. Source: CoolInterview.com
To retrive the data from the Resultset First we create object for the ResultSet for that ResultSet rs=st.executeQuery("sql query");
rs.methods belongs to ResultSet interface.
*[here 'st' means statement object. when we call st.executeQuery() it returns
the object of ResultSet.] Source: CoolInterview.com
Answered by: p.balakrishna | Date: 5/8/2009
| Contact p.balakrishna
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|