1:   What is the difference between Database and Database management system?
Ans:    Database is a collection of interrelated data. Database management system is a software which can be used to manage the data by storing it on to the data base and by retrieving it from the data base.  And  DBMS is a collection of interrelated data and some set of programs to access the data.

            There are 3 types of Database Management Systems.

2: How a query could be executed when we send a query to Database?
When we send an SQL Query from SQL prompt to the DataBaseEngine, then Database Engine will take the following steps.

3: What is  Driver? How many Drivers are available in JDBC? What are the types?

Driver:

Types of Drivers:
            There are 180+  number of Drivers in the market. But all these Drivers could be classified into the following 4 types.

Type 1 Driver:

Advantages:

Dis advantages:

Type 2 Driver:

            Type 2 Driver is also called as “part java part native Driver”. i.e., this Driver was designed by using some part of the java implementations and some other part of the database vendor provided native implementations. This Driver is also called as “native driver”.

Advantages:
            When compared to Type 1 driver it is efficient driver why because Type 2 driver directly will convert java api calls to database vendor api calls.

Dis advantages:

Type 3 Driver: 

Advantages:

Dis advantages:

Type 4 Driver:


4: What is JDBC and What are the steps to write a JDBC application?
           
The process of interacting with the database from a java application is called as JDBC(Java Database Connectivity)
To interact with the database from a java application we will use the following five   steps.

  1. load and register the driver.
  2. Establish a connection between java application and the database.
  3. prepare either statement object or PreparedStatement object or CallebleStatement object as per the application requirements.
  4. write and executer the sql queries.
  5. terminate the connection which we have established.

5:  How to load a JDBC driver? 

Start/ conrlol panel / performance and maintenance / administrative tools / data source(Odbc)/ user dsn / click on Add / select microsofr Odbc for oracle / finish / provide data source name only / click on ok / ok.

Public void forName(String class name)

Eg:    Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);

      Where forName() is a static method, which can be used to load the respective driver class byte code to the memory.

Note:-   The best alternative for Class.forName(..) is
 DriverManagre.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
  To register the driver.

6:    How to establish a Database connection between java application and Database?

If we want to establish a connection between java application and the database we will the following piece of code.

Connection con= DriverManager.getConnection(“jdbc:odbc:nag”,”nag”,”system”,”manager”);

Where getConnectin() is a static method from DriverManager class, which can be used to return connection object.

7:  Basically Connection is an interface, how getConnection() will create an object for
      Connection interface?

Ans:   Connection is an interface from java.sql package, for which getConnection(_)  was return an anonymous inner class object of the Connection interface.

Note:-  Anonymous inner class is a nameless inner class, which can be sued to provide an implementation either for the interfaces or for abstract classes.

Eg:   interface I
         {
                void m1();
          }
         Class Outer
         {
                     I  i = new I(){
                                             public void m1()
                                             {
                                            
                                             }
                                             public void m2()
                                             {

}
                                           }
            }
            Outer o = new Outer();
            o.i.m1();   à  correct
            o.i.m2();   à  wrong

                        getConnection(_) is a static method from DriverManager class, which will call internally  connect() method, this connect() will establish a virtual socket connection in between the java application and the database.
8:   What is the requirement to use Statement object?

public  Statement createStatement()
Eg:     Statement st = con.createStatement();

9:  How to  execute SQL Queries from a java application?

To execute the sql queries we will use the following methods from Statement object.

10:  What are the differences between executeQuery(…), executeUpdate(…) and execute(…)
      methods?

Ans:    where executeQuery() can be used to execute selection group sql queries to fetch the data from database.
When we use selection group sql query with executeQuery() then JVM will send that sql query to the database engine, database engine will execute it, by this database engine(DBE) will fetch the data from database and send back to the java application.
Java is a purely object oriented technology. That’s why the jdbc application will maintain the fetched data from database, in the form of an object at heap memory, called as ResultSet object.

            public  ResultSet executeQuery(String sqlquery)

            where executeUpdate() can be used to execute updation group sql query to update the database. When we provide updation group sql query as a parameter to executeUpdate(), then JVM will send that sql query to DBE, here DBE will execute it and perform updations on the database, by this DBE will identify the number of records got updated value called as “records updated count” and return back to the java application.

            public int executeUpdate(String sqlquery)

            where execute() can be used to execute either selection group sql queries or updation group queries.
            When we use selection group sql query with the execute() then we will get ResultSet object at heap memory with the fetched data. But execute() will return “true” as a Boolean value.
            When we use updation group sql query with execute() then we will get “ records updated count value” at jdbc application. But execute() will return “false” as a Boolean value.

            public  boolean execute(String sqlquery)