JDBC stands for Java Database Connectivity. JDBC is a Java API that is used to connectivity
between java programming language and database. JDBC API uses JDBC drivers to
connect to the database.
1) What are the JDBC Drivers?
JDBC driver is an interface that enables a Java application
to interact with a database. There are
4 types of JDBC drivers:
1.
JDBC-ODBC
bridge driver
2.
Native-API
driver
3.
Network
Protocol driver
4.
Database-Protocol driver
2) What are the common JDBC API components?
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("db_name,user_id,password ");
String q="insert into user values( query )";
Statement stmt=con.createStatement();
ResultSet res=stmt.executeQuery(q);
Ø Connection
Ø Statement
Ø PreparedStatement
Ø ResultSet
Ø ResultSetMetaData
Ø DatabaseMetaData
Ø CallableStatement
Ø DriverManager
3) What is the Connection Interface?
Connection interface represents a session with a specific database,
connection object is used to create the database connection and close the database
connection.
4) What is the role of JDBC DriverManager class?
The
DriverManager provides a basic service for managing a set of database drivers. By
using getConnection() method it establish a connection to the given
database.
5)What is the role of Statement interface in JDBC?
Statement is an interface. Statement object is used for executing a static SQL statement.
6) What is the ResultSet interface in JDBC?
ResultSet object hold the data retrieved from a database by executing a Statement.
7) What is the ResultSetMetaData interface?
ResultSetMetaData
object can be used to find out about the types and properties of the columns (total number of columns, column name, and column type)
in a ResultSet.
8) What is the DatabaseMetaData interface?
DatabaseMetaData provides information about the
database such as username, driver name, driver
version, number of tables etc.
9) What is the role of PreparedStatement interface in
JDBC?
SQL
statement is pre-compiled and stored in a PreparedStatement object. This object
can be used to efficiently execute this statement multiple times.
10) What is the CallableStatement interface?
CallableStatement
is used to execute SQL stored procedures.
11) What is the difference between Statement and
PreparedStatement?
Statement
|
PreparedStatement
|
Query is compiled each
time for every execution
|
Query is compile one time
and execute many times
|
12) What are the steps to create and connect to the Database?
- Class class is used to register the driver class.
- DriverManager class is used to establish connection with the database.
- Connection interface is used to create statement. The statement object is responsible to execute queries.
- ResultSet is used to store all the records of a table.
- Close the connection.
No comments:
Post a Comment