Question-201. What are the steps to connect to the database in java ?

Answer-

  1.  Registering the driver class
  2. Creating connection
  3. Creating statement
  4. Executing queries
  5. Closing connection

 

Question-202. What are the JDBC API components ?

Answer- The java.sql package contains interfaces and classes for JDBC API.

Interfaces:

Connection
Statement
PreparedStatement
ResultSet
ResultSetMetaData
DatabaseMetaData
CallableStatement etc.
Classes:

DriverManager
Blob
Clob
Types
SQLException etc.

 

Question-203. What are the JDBC statements ?

Answer- There are 3 JDBC statements.

Statement
PreparedStatement
CallableStatement

Question-204. What is the difference between Statement and PreparedStatement interface ?

Answer- In case of Statement, query is complied each time whereas in case of PreparedStatement, query is complied only once. So performance of PreparedStatement is better than Statement.

Question-205. How can we execute stored procedures and functions ?

Answer- By using Callable statement interface, we can execute procedures and functions.

Question-206. What is the role of JDBC DriverManager class ?

Answer- The DriverManager class manages the registered drivers. It can be used to register and unregister drivers. It provides factory method that returns the instance of Connection.

Question-207. What does the JDBC Connection interface ?

Answer- The Connection interface maintains a session with the database. It can be used for transaction management. It provides factory methods that returns the instance of Statement, PreparedStatement, CallableStatement and DatabaseMetaData.

Question-208. What does the JDBC ResultSet interface ?

Answer- The ResultSet object represents a row of a table. It can be used to change the cursor pointer and get the information from the database.

Question-209. What does the JDBC ResultSetMetaData interface ?

Answer- The ResultSetMetaData interface returns the information of table such as total number of columns, column name, column type etc.

Question-210. What does the JDBC DatabaseMetaData interface ?

Answer- The DatabaseMetaData interface returns the information of the database such as username, driver name, driver version, number of tables, number of views etc.