Skip to content

Commit 4a70835

Browse files
committed
Update JDBC-questions.md
1 parent 4110f56 commit 4a70835

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

JDBC-questions.md

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
## JDBC Interview Questions
1+
# JDBC Interview Questions
22

33

4-
#### Q. What is DAO factory design pattern in Java?
4+
## Q. What is DAO factory design pattern in Java?
55
Data Access Object Pattern or DAO pattern is used to separate low level data accessing API or operations from high level business services.
66

77
DAO pattern is based on abstraction and encapsulation design principles and shields rest of application from any change in the persistence layer e.g. change of database from Oracle to MySQL, change of persistence technology e.g. from File System to Database.
@@ -121,7 +121,7 @@ Student: [RollNo : 0, Name : Michael ]
121121
<b><a href="#">↥ back to top</a></b>
122122
</div>
123123

124-
#### Q. What are the differences between ResultSet and RowSet?
124+
## Q. What are the differences between ResultSet and RowSet?
125125
A **ResultSet** maintains a connection to a database and because of that it can’t be serialized and also we cant pass the Resultset object from one class to other class across the network.
126126

127127
**RowSet** is a disconnected, serializable version of a JDBC ResultSet and also the RowSet extends the ResultSet interface so it has all the methods of ResultSet. The RowSet can be serialized because it doesn’t have a connection to any database and also it can be sent from one class to another across the network.
@@ -134,7 +134,7 @@ A **ResultSet** maintains a connection to a database and because of that it can
134134
|ResultSet object is not a JavaBean object You can create/get a result set using the executeQuery() method.|ResultSet Object is a JavaBean object. You can get a RowSet using the RowSetProvider.newFactory().createJdb cRowSet() method.|
135135
|By default, ResultSet object is not scrollable or, updatable.|By default, RowSet object is scrollable and updatable.|
136136

137-
#### Q. How can we execute stored procedures using CallableStatement?
137+
## Q. How can we execute stored procedures using CallableStatement?
138138
**CallableStatement** interface in java is used to call stored procedure from java program. **Stored Procedures** are group of statements that we compile in the database for some task. Stored procedures are beneficial when we are dealing with multiple tables with complex scenario and rather than sending multiple queries to the database, we can send required data to the stored procedure and have the logic executed in the database server itself.
139139

140140
A CallableStatement object provides a way to call stored procedures using JDBC. Connection.prepareCall() method provides you CallableStatement object.
@@ -188,7 +188,7 @@ public class Proc {
188188
<b><a href="#">↥ back to top</a></b>
189189
</div>
190190

191-
#### Q. What are the differences between Statement and PreparedStatement interface?
191+
## Q. What are the differences between Statement and PreparedStatement interface?
192192
JDBC API provides 3 different interfaces to execute the different types of SQL queries. They are,
193193

194194
* **Statement** – Used to execute normal SQL queries.
@@ -241,7 +241,7 @@ cstmt.execute();
241241
<b><a href="#">↥ back to top</a></b>
242242
</div>
243243

244-
#### Q. What are the different types of locking in JDBC?
244+
## Q. What are the different types of locking in JDBC?
245245
The types of locks in JDBC:
246246

247247
**1. Row and Key Locks**: Useful when updating the rows (update, insert or delete operations), as they increase concurrency.
@@ -255,7 +255,7 @@ The types of locks in JDBC:
255255

256256
**4. Database Lock**: In order to prevent the read or update access from other transactions when the database is open, the database lock is used.
257257

258-
#### Q. What are the differences between Stored Procedure and functions?
258+
## Q. What are the differences between Stored Procedure and functions?
259259
|Functions |Procedures |
260260
|--------------------------|-------------------------------------------------|
261261
|A function has a return type and returns a value.|A procedure does not have a return type. But it returns values using the OUT parameters.|
@@ -269,7 +269,7 @@ The types of locks in JDBC:
269269
<b><a href="#">↥ back to top</a></b>
270270
</div>
271271

272-
#### Q. What is batch processing and how to perform batch processing in JDBC?
272+
## Q. What is batch processing and how to perform batch processing in JDBC?
273273
Batch Processing allows to group related SQL statements into a batch and submit them with one call to the database. The `java.sql.Statement` and `java.sql.PreparedStatement` interfaces provide methods for batch processing.
274274

275275
* **addBatch()**: The addBatch() method of Statement, PreparedStatement, and CallableStatement is used to add individual statements to the batch.
@@ -353,7 +353,7 @@ conn.commit();
353353
<b><a href="#">↥ back to top</a></b>
354354
</div>
355355

356-
#### Q. What is database connection pooling? What are the advantages of using a connection pool?
356+
## Q. What is database connection pooling? What are the advantages of using a connection pool?
357357
**Connection pooling** means that connections are reused rather than created each time a connection is requested. To facilitate connection reuse, a memory cache of database connections, called a connection pool, is maintained by a connection pooling module as a layer on top of any standard JDBC driver product.
358358

359359
Connection pooling is performed in the background and does not affect how an application is coded; however, the application must use a DataSource object (an object implementing the DataSource interface) to obtain a connection instead of using the DriverManager class.
@@ -488,7 +488,7 @@ public class ConnectionPool {
488488
<b><a href="#">↥ back to top</a></b>
489489
</div>
490490

491-
#### Q. What is JDBC Driver?
491+
## Q. What is JDBC Driver?
492492
JDBC Driver is a software component that enables java application to interact with the database. There are 4 types of JDBC drivers:
493493

494494
* JDBC-ODBC bridge driver
@@ -518,7 +518,7 @@ The thin driver converts JDBC calls directly into the vendor-specific database p
518518
<b><a href="#">↥ back to top</a></b>
519519
</div>
520520

521-
#### Q. What are the JDBC API components?
521+
## Q. What are the JDBC API components?
522522

523523
The JDBC API provides the following interfaces and classes −
524524

@@ -534,7 +534,7 @@ The JDBC API provides the following interfaces and classes −
534534

535535
* **SQLException**: This class handles any errors that occur in a database application.
536536

537-
#### Q. What is JDBC ResultSetMetaData interface?
537+
## Q. What is JDBC ResultSetMetaData interface?
538538
ResultSetMetaData is an interface in **java.sql** package of JDBC API which is used to get the metadata about a ResultSet object. Whenever we query the database using SELECT statement, the result will be stored in a ResultSet object. Every ResultSet object is associated with one ResultSetMetaData object. This object will have all the meta data about a ResultSet object like schema name, table name, number of columns, column name, datatype of a column etc. We can get this ResultSetMetaData object using **getMetaData()** method of ResultSet.
539539

540540
```java
@@ -573,7 +573,7 @@ Column Type Name of 1st column: NUMBER
573573
<b><a href="#">↥ back to top</a></b>
574574
</div>
575575

576-
#### Q. What is JDBC DatabaseMetaData interface?
576+
## Q. What is JDBC DatabaseMetaData interface?
577577
DatabaseMetaData interface provides methods to get meta data of a database such as database product name, database product version, driver name, name of total number of tables, name of total number of views etc.
578578

579579
| Methods | Description |
@@ -623,7 +623,7 @@ Driver Name: Oracle JDBC Driver
623623
<b><a href="#">↥ back to top</a></b>
624624
</div>
625625

626-
#### Q. How can we set null value in JDBC PreparedStatement?
626+
## Q. How can we set null value in JDBC PreparedStatement?
627627
Use the **setNull()** method to bind null to the parameter. The setNull() method accepts two parameter, index and the sql type as arguments.
628628

629629
```java
@@ -661,6 +661,7 @@ public class Main {
661661
}
662662
}
663663
```
664+
664665
<div align="right">
665666
<b><a href="#">↥ back to top</a></b>
666667
</div>
@@ -682,6 +683,7 @@ public class Main {
682683
#### Q. Explain optimistic and pessimistic locking in JDBC?
683684
#### Q. How can we store and retrieve images from the database?
684685
#### Q. How can we store and retrieve the file in the Oracle database?
686+
685687
<div align="right">
686688
<b><a href="#">↥ back to top</a></b>
687689
</div>

0 commit comments

Comments
 (0)