Search

Useful Links

Monday, September 12, 2011

JDBC Interview Question - Part 2

. What are the steps required to execute a query in JDBC?
First we need to create an instance of a JDBC driver or load JDBC drivers, then we need to register this driver with DriverManager class. Then we can open a connection. By using this connection , we can create a statement object and this object will help us to execute the query.
5. What is DriverManager ?
DriverManager is a class in java.sql package. It is the basic service for managing a set of JDBC drivers.
6. What is a ResultSet ?
A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set.

Also,

Resulset could be defined in three ways.
TYPE_SCROLL_SENSITIVE (can scroll forward or backward and sensitive to the changes made in the database)
TYPE_SCROLL_INSENSITIVE ( can scroll forward and backward but insensitive to database changes; It is actually snapshot of database so once data fetched not changed)
TYPE_FORWARD_ONLY (can move only in forward direction)

No comments:

Post a Comment