You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: JDBC-questions.md
+16-14
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
-
##JDBC Interview Questions
1
+
# JDBC Interview Questions
2
2
3
3
4
-
####Q. What is DAO factory design pattern in Java?
4
+
## Q. What is DAO factory design pattern in Java?
5
5
Data Access Object Pattern or DAO pattern is used to separate low level data accessing API or operations from high level business services.
6
6
7
7
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 ]
121
121
<b><a href="#">↥ back to top</a></b>
122
122
</div>
123
123
124
-
####Q. What are the differences between ResultSet and RowSet?
124
+
## Q. What are the differences between ResultSet and RowSet?
125
125
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.
126
126
127
127
**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
134
134
|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.|
135
135
|By default, ResultSet object is not scrollable or, updatable.|By default, RowSet object is scrollable and updatable.|
136
136
137
-
####Q. How can we execute stored procedures using CallableStatement?
137
+
## Q. How can we execute stored procedures using CallableStatement?
138
138
**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.
139
139
140
140
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 {
188
188
<b><a href="#">↥ back to top</a></b>
189
189
</div>
190
190
191
-
####Q. What are the differences between Statement and PreparedStatement interface?
191
+
## Q. What are the differences between Statement and PreparedStatement interface?
192
192
JDBC API provides 3 different interfaces to execute the different types of SQL queries. They are,
193
193
194
194
***Statement** – Used to execute normal SQL queries.
@@ -241,7 +241,7 @@ cstmt.execute();
241
241
<b><a href="#">↥ back to top</a></b>
242
242
</div>
243
243
244
-
####Q. What are the different types of locking in JDBC?
244
+
## Q. What are the different types of locking in JDBC?
245
245
The types of locks in JDBC:
246
246
247
247
**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:
255
255
256
256
**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.
257
257
258
-
####Q. What are the differences between Stored Procedure and functions?
258
+
## Q. What are the differences between Stored Procedure and functions?
|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:
269
269
<b><a href="#">↥ back to top</a></b>
270
270
</div>
271
271
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?
273
273
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.
274
274
275
275
***addBatch()**: The addBatch() method of Statement, PreparedStatement, and CallableStatement is used to add individual statements to the batch.
@@ -353,7 +353,7 @@ conn.commit();
353
353
<b><a href="#">↥ back to top</a></b>
354
354
</div>
355
355
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?
357
357
**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.
358
358
359
359
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 {
488
488
<b><a href="#">↥ back to top</a></b>
489
489
</div>
490
490
491
-
####Q. What is JDBC Driver?
491
+
## Q. What is JDBC Driver?
492
492
JDBC Driver is a software component that enables java application to interact with the database. There are 4 types of JDBC drivers:
493
493
494
494
* JDBC-ODBC bridge driver
@@ -518,7 +518,7 @@ The thin driver converts JDBC calls directly into the vendor-specific database p
518
518
<b><a href="#">↥ back to top</a></b>
519
519
</div>
520
520
521
-
####Q. What are the JDBC API components?
521
+
## Q. What are the JDBC API components?
522
522
523
523
The JDBC API provides the following interfaces and classes −
524
524
@@ -534,7 +534,7 @@ The JDBC API provides the following interfaces and classes −
534
534
535
535
***SQLException**: This class handles any errors that occur in a database application.
536
536
537
-
####Q. What is JDBC ResultSetMetaData interface?
537
+
## Q. What is JDBC ResultSetMetaData interface?
538
538
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.
539
539
540
540
```java
@@ -573,7 +573,7 @@ Column Type Name of 1st column: NUMBER
573
573
<b><a href="#">↥ back to top</a></b>
574
574
</div>
575
575
576
-
####Q. What is JDBC DatabaseMetaData interface?
576
+
## Q. What is JDBC DatabaseMetaData interface?
577
577
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.
0 commit comments