Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Practice InterviewNew Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

JDBC Interview Questions and Answers

Ques 11. How can you retrieve data from the ResultSet?

Ans. 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.
ResultSet rs = stmt.executeQuery("SELECT NAME,SAL FROM EMPLOYEE");
String s = rs.getString("NAME");

The method getString is invoked on the ResultSet object rs, so getString() will retrieve (get) the value stored in the column NAME in the current row of rs.

Is it helpful? Add Comment View Comments
Ques 12. What are the different types of Statements?
Ans. Regular statement (use createStatement method), prepared statement (use prepareStatement method) and callable statement (use prepareCall)
Is it helpful? Add Comment View Comments
Ques 13. How can you use PreparedStatement?
Ans. This special type of statement is derived from class Statement.If you need a
Statement object to execute many times, it will normally make sense to use a PreparedStatement object instead. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatementís SQL statement without having to compile it first.
PreparedStatement updateSales =
con.prepareStatement("UPDATE EMPLOYEE SET SAL=? WHERE EMP_ID=?");
Is it helpful? Add Comment View Comments
Ques 14. What does setAutoCommit do?
Ans. When a connection is created, it is in auto-commit mode. This means that each individual SQL statement is treated as a transaction and will be automatically committed right after it is executed. The way to allow two or more statements to be grouped into a transaction is to disable auto-commit mode:

Once auto-commit mode is disabled, no SQL statements will be committed until you call the method commit explicitly.

PreparedStatement updateSales =
con.prepareStatement( "UPDATE EMPLOYEE SET SAL = ? WHERE EMP_NAME LIKE ?");
updateSales.setInt(1, 50000); updateSales.setString(2, "Arindam");
PreparedStatement updateTotal =
updateTotal.setInt(1, 50000);
updateTotal.setString(2, "Arindam");
Is it helpful? Add Comment View Comments
Ques 15. How do you call a stored procedure from JDBC?
Ans. The first step is to create a CallableStatement object. As with Statement an and PreparedStatement objects, this is done with an open
Connection object. A CallableStatement object contains a call to a stored procedure.
CallableStatement cs = con.prepareCall("{call SHOW_EMPLOYEES}");
ResultSet rs = cs.executeQuery();
Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2020 WithoutBook