JDBC Questions
JDBC Questions
1.What is JDBC?
JDBC is an acronym for Java Database Connectivity, it is an API which helps to connect a java program or
application to the database.
4.Explain Class.forName()
The forName() method of java.lang.Class class is used to get the instance of this Class with the specified
class name. This class name is specified as the string parameter.
Syntax:
public static Class<T> forName(String className) throws ClassNotFoundException
Parameter:
This method accepts the parameter className which is the Class for which its instance is required.
Return Value:
This method returns the instance of this Class with the specified class name.
6.What are the different ways of loading and registering the drivers in JDBC.
To connect with a database using JDBC we need to select, get the driver for the respective database and
register the driver.
You can register a database driver in two ways −
1.Using Class.forName() method −
The forName() method of the class named Class accepts a class name as a String parameter and loads it into
the memory, soon it is loaded into the memory it gets registered automatically.
2. Using the registerDriver() method −
The registerDriver() method of the DriverManager class accepts an object of the diver class as a parameter
and, registers it with the JDBC driver manager.
7.What are the different ways of getting a connection object in JDBC.
JDBC application connects to a target data source using one of two classes:
DriverManager:
This fully implemented class connects an application to a data source, which is specified by a database URL.
Connecting to your DBMS with the DriverManager class involves calling the
method DriverManager.getConnection() which returns connection object.
When this class first attempts to establish a connection, it automatically loads any JDBC 4.0 drivers found.
Data Source:
Objects instantiated by classes that implement the Data Source represent a particular DBMS or some other
data source, such as a file.
9.Explain with an example how to read the data from properties file?
To get information from the properties file, create the properties file first.
example,
Now, let's create the java class to read the data from the properties file.
13.What is Statement?
The statement interface is used to create SQL basic statements in Java it provides methods to execute
queries with the database.
There are different types of statements that are used in JDBC as follows:
1. Create Statement
2. Prepared Statement
3. Callable Statement
24.Name some of the encrypting and decrypting algorithm which are widely used in
industries.
1. Triple DES - Data Encryption Standard (DES)- The algorithm uses a 56-bit individual key with the total
key length adding up to 168 bits.
2. RSA - Rivest-Shamir-Adleman (RSA)- The keys for the RSA algorithms are generated by multiplying the
large number and creating a modulus.
3. Blowfish- The length of the keys can be anywhere from 32 bits to 448 bits, and so far, the encryption has
never been defeated.
4. Twofish- It uses block encrypting and splits the data into blocks that are 128 bits long, and the key is
applied simultaneously to all blocks. The key for the encryption can be 256 bits long.
5. AES - Advanced Encryption Standard (AES)- It is highly efficient in its basic 128-bit form and uses 192
and 256-bit keys for some robust encryption.
25.How does AES work?
The AES algorithm (also known as the Rijndael algorithm) is a symmetrical block cipher algorithm that
takes plain text in blocks of 128 bits and converts them to ciphertext using keys of 128, 192, and 256 bits.
Since the AES algorithm is considered secure, it is in the worldwide standard.
The AES algorithm uses a substitution-permutation, or SP network, with multiple rounds to produce
ciphertext. The number of rounds depends on the key size being used. A 128-bit key size dictates ten
rounds, a 192-bit key size dictates 12 rounds, and a 256-bit key size has 14 rounds. Each of these rounds
requires a round key, but since only one key is inputted into the algorithm, this key needs to be expanded
to get keys for each round, including round 0.
Each round in the algorithm consists of four steps.
Substitution of the bytes
In the first step, the bytes of the block text are substituted based on rules dictated by predefined S-boxes
Shifting the rows
Next comes the permutation step. In this step, all rows except the first are shifted by one
Mixing the columns
In the third step, the Hill cipher is used to jumble up the message more by mixing the block’s columns.
Adding the round key
In the final step, the message is XORed with the respective round key.
When done repeatedly, these steps ensure that the final ciphertext is secure.