A good way to find out what JDBC calls are doing is to enable JDBC tracing. The JDBC trace contains a detailed listing of the activity occurring in the system that is related to JDBC operations.
If you use the DriverManager facility to establish your database connection, you use the DriverManager. setLogWriter method to enable tracing of JDBC operations. If you use a DataSource object to get a connection, you use the DataSource.setLogWriter method to enable tracing. (For pooled connections, you use the ConnectionPoolDataSource.setLogWriter method, and for connections that can participate in distributed transactions, you use the XADataSource.setLogWriter method.)
Posted Date:- 2021-09-04 05:19:48
There are three types of parameters available in Stored Procedures. They are:
1. IN: Used to pass the input values to the procedure.
2. OUT: Used to get the value from the procedure.
3. IN/OUT: Used to pass the input values and get the value to/from the procedure.
Posted Date:- 2021-09-04 05:18:28
The JDBC 3.0 API is the latest update of the JDBC API. It contains many features, including scrollable result sets and the SQL:1999 data types.
JDBC (Java Database Connectivity) is the standard for communication between a Java application and a relational database. The JDBC API is released in two versions; JDBC version 1.22 (released with JDK 1.1.X in package java.sql) and version 2.0 (released with Java platform 2 in packages java.sql and javax.sql). It is a simple and powerful largely database-independent way of extracting and inserting data to or from any database.
Posted Date:- 2021-09-04 05:17:10
Sometimes a table can have auto generated keys used to insert the unique column value for primary key. We can use Statement getGeneratedKeys() method to get the value of this auto generated key.
Posted Date:- 2021-09-04 05:16:18
We can use PreparedStatement setNull() method to bind the null variable to a parameter. The setNull method takes index and SQL Types as argument, for example
ps.setNull(10, java.sql.Types.INTEGER);.
Posted Date:- 2021-09-04 05:15:34
1. SQLNonTransientException
2. SQLTransientException
3. SQLRecoverableException
Posted Date:- 2021-09-04 05:14:38
Savepoint is used to create checkpoints in a transaction, and it allows us to perform a rollback to the specific savepoint. Once the transaction is committed or rolled backed, the savepoint that has been created for a transaction will be automatically destroyed and becomes invalid.
Posted Date:- 2021-09-04 05:12:23
By default, the value of AutoCommit is TRUE. After the execution of the SQL statement, it will be committed automatically. Using the setAutoCommit() method, we can change the value to AutoCommit.
Posted Date:- 2021-09-04 05:10:50
Two types of packages are available in JDBC API
1. java.sql
2. javax.sql
Posted Date:- 2021-09-04 05:10:08
It is an interface between user and drivers. DriverManager tracks all the activity between a database and the appropriate driver.
Posted Date:- 2021-09-04 05:09:08
execute(): it can be used for any kind of SQL Query.
executeQuery() : it can be used for select query.
executeUpdate(): it can be used to change/update table.
Posted Date:- 2021-09-04 05:07:28
Metadata means data or information about other data. We use metadata to get database product version, driver name, the total number of tables and views.
Posted Date:- 2021-09-04 05:06:47
No, we cannot get null Resultset. ResultSet.next() can return null if the next record does not contain a row.
Posted Date:- 2021-09-04 05:06:13
SQL warning or Database warning is the subclass of SQLException class. We can handle it by using getWarnings() method on Connection, Statement, and ResultSet.
Posted Date:- 2021-09-04 05:05:33
If you want to turn Off the Auto Commit then set connection.setAutoCommit(false)
Posted Date:- 2021-09-04 05:04:57
JDBC DriverManager is the factory class through which we get the Database Connection object. When we load the JDBC Driver class, it registers itself to the DriverManager, you can look up the JDBC Driver classes source code to check this.
Then when we call DriverManager.getConnection() method by passing the database configuration details, DriverManager uses the registered drivers to get the Connection and return it to the caller program.
Posted Date:- 2021-09-04 05:03:42
The BatchUpdates feature allows us to group SQL statements together and send to database server in one single trip.
Posted Date:- 2021-09-04 05:03:09
No, we can open only one Statement object when using the JDBC-ODBC Bridge.
Posted Date:- 2021-09-04 05:02:30
This question is not directly related to JDBC but some time asked during JDBC interviews. The cold back is the backup technique in which backup of files are taken before the database is restarted. In hot backup of files and table is taken at the same time when the database is running. A warm is a recovery technique where all the tables are locked and users cannot access at the time of backing up data.
Posted Date:- 2021-09-04 05:01:44
This is also one of the most popular question asked during JDBC Interviews. Connection pooling is the mechanism by which we reuse the recourse like connection objects which are needed to make connection with database .In this mechanism client are not required every time make new connection and then interact with database instead of that connection objects are stored in connection pool and client will get it from there. so it’s a best way to share a server resources among the client and enhance the application performance.
Posted Date:- 2021-09-04 05:01:15
Another tough JDBC Interview question, not many Java programmer knows about using Cursor in Java. in JDBC 2.0 API new feature is added to move cursor in resultset backward forward and also in a particular row .
There are three constant define in result set by which we can move cursor.
· TYPE_FORWARD_ONLY: creates a non-scrollable result set, that is, one in which the cursor moves only forward
· TYPE_SCROLL_INSENSITIVE : a scrollable result set does not reflects changes that are made to it while it is open
· TYPE_SCROLL_SENSITIVE: a scrollable result set reflects changes that are made to it while it is open
Posted Date:- 2021-09-04 04:51:45
This is one of the most popular JDBC Interview questions and asked at an advanced level, mostly to senior Java developers on J2EE interviews. Two-phase commit is used in a distributed environment where multiple processes take part in the distributed transaction process. In simple word we can understand like if any transaction is executing and it will affect multiple databases then a two-phase commit will be used to make all database synchronized with each other.
In two-phase commit, commit or rollback is done by two phases:
1. Commit request phase: in this phase main process or coordinator process take vote of all other process that they are complete their process successfully and ready to commit if all the votes are “yes†then they go ahead for next phase. And if “No “then rollback is performed.
2. Commit phase: according to vote if all the votes are yes then commit is done.
Similarly when any transaction changes multiple database after execution of transaction it will issue pre commit command on each database and all database send acknowledgement and according to acknowledgement if all are positive transaction will issue the commit command otherwise rollback is done .
Posted Date:- 2021-09-04 04:50:51
This kind of JDBC interview question is asked on 2 to 4 years experience Java programmer, they are expected to familiar with database transaction and isolation level etc. As the name it self convey the meaning of dirty read “read the value which may or may not be correctâ€. in database when one transaction is executing and changing some field value same time some another transaction comes and read the change field value before first transaction commit or rollback the value ,which cause invalid value for that field, this scenario is known as dirty read.
Posted Date:- 2021-09-04 04:50:14
JDBC API uses Java Reflection API to achieve loose coupling between java programs and JDBC Drivers. If you look at a simple JDBC example, you will notice that all the programming is done in terms of JDBC API and Driver comes in picture only when it’s loaded through reflection using Class.forName() method.
Posted Date:- 2021-09-04 04:49:36
Java DataBase Connectivity API allows us to work with relational databases. JDBC API interfaces and classes are part of java.sql and javax.sql package. We can use JDBC API to get the database connection, run SQL queries and stored procedures in the database server and process the results.
JDBC API is written in a way to allow loose coupling between our Java program and actual JDBC drivers that make our life easier in switching from one database to another database servers easily.
Posted Date:- 2021-09-04 04:48:40
In a ResultSet handle connection to a DB, we cannot make Result as a serialized object.
Because of above issue, we cannot pass Resultset across the network.
RowSet extends the ResultSet interface, so it holds all methods from ResultSet. RowSet is serialized.
So, we can pass Rowset from one class to another class because it has no connection with the database.
Posted Date:- 2021-09-04 04:47:30
There are two types of RowSet are there. They are:
1. Connected - A connected RowSet object connects to the database once and remains connected until the application terminates.
2. Disconnected - A disconnected RowSet object connects to the database, executes a query to retrieve the data from the database and then closes the connection. A program may change the data in a disconnected RowSet while it is disconnected. Modified data can be updated in the database after a disconnected RowSet reestablishes the connection with the database.
Posted Date:- 2021-09-04 04:45:09
A RowSet is an object that encapsulates a set of rows from either Java Database Connectivity (JDBC) result sets or tabular data sources like a file or spreadsheet. RowSets support component-based development models like JavaBeans, with a standard set of properties and an event notification .
Posted Date:- 2021-09-04 04:44:17
No. You can open only one Statement object per connection when you are using the JDBC-ODBC Bridge.
Posted Date:- 2021-09-04 04:43:50
JDBC Net pure Java driver(Type IV) is the fastest driver because it converts the JDBC calls into vendor specific protocol calls and it directly interacts with the database.
Posted Date:- 2021-09-04 04:43:23
PL/SQL stored procedures are called from within JDBC programs by means of the prepareCall() method of the Connection object created. A call to this method takes variable bind parameters as input parameters as well as output variables and creates an object instance of the CallableStatement class. The following line of code illustrates this:
CallableStatement stproc_stmt = conn.prepareCall("{call procname(?,?,?)}");
Posted Date:- 2021-09-04 04:42:41
Callable statements are used from JDBC application to invoke stored procedures and functions.
Posted Date:- 2021-09-04 04:42:06
A prepared statement is an SQL statement that is precompiled by the database. Through precompilation, prepared statements improve the performance of SQL commands that are executed multiple times (given that the database supports prepared statements). Once compiled, prepared statements can be customized prior to each execution by altering predefined SQL parameters.
Posted Date:- 2021-09-04 04:41:43
This interface gives more information about ResultSet. Each ResultSet object has been associated with one ResultSetMetaData object.
This object will have the details of the properties of the columns like datatype of the column, column name, the number of columns in that table, table name, schema name, etc., getMetaData() method of ResultSet object is used to create the ResultSetMetaData object.
Syntax:
PreparedStatement pstmntobj = conn.prepareStatement(insert_query);
ResultSet resultsetobj = pstmntobj.executeQuery(“Select * from EMPLOYEEâ€);
ResultSetMetaData rsmd obj= resultsetobj.getMetaData();
Posted Date:- 2021-09-04 04:39:09
<> Statement acts like a vehicle through which SQL commands can be sent. Through the connection object we create statement kind of objects.
<> Through the connection object we create statement kind of objects.
<> Statement stmt = conn.createStatement();
<> This method returns object which implements statement interface.
Posted Date:- 2021-09-04 04:38:19
The connection object represents communication context, i.e., all communication with database is through connection object only.
Posted Date:- 2021-09-04 04:37:25
There are four types of components
1. JDBC API
2. JDBC Driver Manager
3. JDBC Test Suite
4. JDBC-ODBC Bridge
Posted Date:- 2021-09-04 04:36:15
Yes, we can get the data of the particular row from the resultSet using the relative() method. It will move the cursor to the given row either in a forward or in a backward direction from the current row. If the positive value has been given, it will move in the forward direction. If the negative value has been given, it will move in the backward direction.
Posted Date:- 2021-09-04 04:35:08
There are 2 different modes of Concurrency in ResultSet. They are:
1. ResultSet.CONCUR_READ_ONLY: It is the default concurrency mode. A read-only option is available. Updation is not possible.
2. ResultSet.CONCUR_UPDATABLE: Updation is possible.
Posted Date:- 2021-09-04 04:34:08
ResultSet interface is used to store the output data after the SQL query execution. The object of ResultSet maintains the cursor point at the result data. As a default, the cursor points before the first row of the result data. We can traverse the data in the resultset objects as well.
Syntax:
Statement Interface:
Statement stmnt1 = conn.createStatement();
ResultSet resultset = stmnt1.executeQuery(“Select * from EMPLOYEEâ€);
PreparedStatement Interface:
PreparedStatement pstmnt1 = conn.prepareStatement(insert_query);
ResultSet resultset = pstmnt1.executeQuery(“Select * from EMPLOYEEâ€);
Posted Date:- 2021-09-04 04:33:23
We can execute the SQL Stored procedures through the CallableStatement interface. The CallableStatement object can be created using the prepareCall() method of the Connection interface.
Posted Date:- 2021-09-04 04:32:56
DriverManager is an in-built class that is present in the java.sql package. It will be used as a mediator between the Java Application and DB, which we are connecting/using in our code. As a first step, we need to register or load the driver with DriverManager. Then the driver will be available to use in the application.
The main function of DriverManager is to load the driver class of the Database and create a connection with DB.
There are 2 ways to register or load the driver:
<> Class.forName()
<> DriverManager.registerDriver()
Posted Date:- 2021-09-04 04:32:29
There are 6 basic steps to connect with DB in Java. These are enlisted below:
>> Import package
>> Load driver
>> Establish connection
>> Creation and execution of the statement
>> Retrieve results
>> Close connection
Posted Date:- 2021-09-04 04:31:36
>> DatabaseMetaData is an interface that provides methods to obtain information about the database.
>> We can use this for getting database-related informations, such as database name, database version, driver name, the total number of tables or views, etc.
Posted Date:- 2021-09-04 04:30:33
<> BLOB data type is used to store the image in the database. We can also store videos and audio by using the BLOB data type. It stores the binary type of data.
<> CLOB data type is used to store the file in the database. It stores the character type of data.
Posted Date:- 2021-09-04 04:29:27
Type IV Thin driver is used in most of the applications. It is developed by the database vendor itself so the developers can use it directly without depending on any other sources. It allows for simple and easy development. It gives higher performance than the other drivers.
Posted Date:- 2021-09-04 04:27:51
There are 4 different JDBC drivers out there in the market.
They are:
Type I: JDBC – ODBC Bridge
Type II: Native API – Half Java Driver
Type III: Network Protocol– Totally Java Driver
Type IV: Thin Driver- Totally Java Driver
Type I: JDBC-ODBC Bridge
JDBC-ODBC bridge is going to behave as an interface between the client and the DB server. The client should put the JDBC-ODBC driver in it. The database ought to support the ODBC driver. If we are not concerned about the driver installation within the client system, we will use this driver.
Type II: Native API: Half Java Driver
It is almost like a JDBC-ODBC driver. Rather than an ODBC driver, we are using native API here. Libraries of the client-side database are used.
Type III: Network Protocol
It works like a 3-tier approach to access the database. An intermediate server will be used to connect to DB. JDBC method calls send data to an intermediate server then the server will communicate with DB.
Type IV: Thin Driver
It is absolutely written in Java. It explicitly converts JDBC method calls into the vendor-specific database protocol. Nowadays, Database merchant itself is providing this type of driver for their customers. So programmers don’t rely on other sources. It gives higher performance than the other drivers.
Posted Date:- 2021-09-04 04:27:26
>> The java.sql.ResultSet interface represents the database result set, which is obtained after the execution of SQL query using Statement objects.
>> Object of ResultSet maintains a cursor pointing to the current row of data in the result set. Initially, the cursor is located before the first row. Then the cursor is moved to the next row by using the next() method. The next() method can be used to iterate through the result set with the help of a while loop. If there are no further rows, the next() method will return false.
>> Example for the creation of ResultSet is given below:
ResultSet rs = con.executeQuery(sqlQuery);
Posted Date:- 2021-09-04 04:26:34
It is a software component and is used to make the Java application to interact with the Database.
Posted Date:- 2021-09-04 04:23:36
Java Database Connectivity is unofficially known as JDBC. It is used to perform DB operations in Database from Java application. It supports interaction with any kind of DB like Oracle, MySQL, MS Access, etc.
Posted Date:- 2021-09-04 04:23:04