JDBC Interview Q

  • What is JDBC?
JDBC is an API(Application Programming Interface) used to develop a java program that communicates with any DataBase server without changing the code.
  • Can we use C program to communicate with Database?
Yes, we can use C program to communicate with database, but it is able to communicate with only one database.

  • What are CI functions? What is their use?
Every database contains its own CI(Call Interface) functions.
  • What are the two most important packages of JDBC API?
  1. java.sql 
  2. javax.sql
  • What are the steps to develop a JDBC Program?
  1. Register the JDBC Driver.
  2. Establish the Connection with Database Server.
  3. Create a Statement object to send SQL query to the DB server.
  4. Send the query to the DB server with the help of Statement object.
  5. Close the Connection.
  • How to register the JDBC driver? 
We can register the JDBC driver in many ways. Generally we use "registerDriver()" method of 'DriverManager' class to register the JDBC driver. We can also use "class.forName()" method to register the JDBC driver.
  • How to establish a connection between Java program and Database server?
We can establish the connection between Java program and Database server by using a method named "getConnection()", this method belongs to 'DriverManager' class. 
  • How many types of statements are there in JDBC?
There are 3 types of Statements in JDBC, with which we can send the query to the database server. They are: 1.) Statement ,  2.) PreparedStatement ,  3.) CallableStatement.
  • What is the difference between Statement and Prepared Statement?
A statement is parsed and executed each time when it is submitted to database, where as a Prepared Statement is parsed once and executed repeatedly with different parameters. PreparedStatement increases performance when compared to Statement.
  • What are Positional parameters? How are they represented?
Positional Parameters are the parameters that are passed to the Prepared Statement. They are represented by "?".
  • What are the important classes and interfaces in JDBC API?
  • How to retrieve data from Database server?
We use ResultSet to retrieve records from Database server. The retrieved records will be stored in ReslutSet Object. 
  • How to extract the records from ResultSet Object?
ResultSet Interface provides "next()" method to retrieve records from ResultSet Object. we can use this method in loop to extract records from ResultSet object. 
  • How many types of ResultSet objects are there? what are they?
There are two types of ResultSet objects, they are: 1.) Forward ResultSet 2.) Scrollable ResultSet.
  • What is the difference between Forward ResultSet and Scrollable ResultSet?
Forward ResultSet can retrieve the records sequentially, where as Scrollable ResultSet can retrieve the records randomly. 
  • Can we store Images and Files in to Database using Java application?
Yes, we can store images and files. SQL provides us a datatypes called BLOB(Binary Large Object) to store Images into database and CLOB (Character Large Object) to store Files into database.  



No comments:

Post a Comment