JDBC Java Interview Questions
1 what is JDBC driver?
it’s a software component that enables Java application to interact with the databases/
there are four types of JDBC drivers:

2 the steps to connect a database in Java?
register the drive class
create connection
create statement
execute queries
close connection
3 what are the JDBC API components?
the java.sql package contains interfaces and classes for JDBC API.
what interfaces does it included?
connection
statement
PreparedStatement
ResultSet
ResultSetMetaData
DatabaseMetaData
callableStatement etc
what classes does it included?
driverManager
Blob
Clob
Types
SQLExeception etc
4 what is JDBC driverManager class?
it manages the register drivers. It can be used to register and unregister drivers. It provides factory method that return the instance of connection.
5 what is JDBC connection interface?
It 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.

6 the purpose of JDBC resultSet interface?
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.
7 JDBC resultSetMetaData interface?
it returns the information of table such as total number of columns, column name, column type etc.(就是说表的一些meta信息,比如说表的大小,列名或者数据名)
8 JDBC DatabaseMetaData interface?
returns the information of the database such as username, driver name, driver version, number of tables, number of views etc.
9 what is batching processing in JDBC?
it helps you to group related SQL statement into a batch and execute them instead of executing a single query. (the purpose is execute multiple queries which makes it faster)
10 the diff between execute, executeQuery, executeUpdate?
Execute: used to execute any SQL query and it returns true if the result is an ResultSet such as running Select queries.
executeQuery: used to execute select queries and returns the resultSet.
executeUpdate: used to execute Insert/Update/Delete (DML) statements or DDL statements that returns nothing.
11 what is JDBC statement?
it used to send SQL commands to the database and retrieve data back from the database.
those statement includes: execute(), executeUpdate(), executeQuery. those are provided by JDBC to interact with database.
There are three types of statements:
Statement: used for general purpose access to the database and executes astatic SQL query at runtime.
PreparedStatement: Used to provide input paramenters to the query during execution.
CallableStatement: Used to access the database stored procedures and helps in accepting runtime parameters.

浙公网安备 33010602011771号