JAVA JDBC Programming Question:
Download Job Interview Questions and Answers PDF
How can you retrieve data from the ResultSet using JDBC?
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
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
Download JDBC Interview Questions And Answers
PDF
Previous Question | Next Question |
How can you create JDBC statements? | What are the different types of Statements in JDBC? |