JDBC Interview Questions And Answers


Q1. What are the steps to connect to the database in java?

What are the steps to connect to the database in java
What are the steps to connect to the database in java




Q2. What is JDBC Driver?

What is JDBC Driver
What is JDBC Driver




Q3. What are the different JDBC API components?

What are the different JDBC API components
What are the different JDBC API components




Q4. What is the difference between execute, executeQuerry, executeUpdate?

What is the difference between execute, executeQuerry, executeUpdate
What is the difference between execute, executeQuerry, executeUpdate




Q5. What is JDBC Connection interface?

What is JDBC Connection interface
What is JDBC Connection interface


Q6. What is auto-commit in JDBC?

It is a feature of JDBC api that makes sure that every update on the database is made permanent. It can be disabled or enabled programmatically by calling the "setAutocommit(false)// disables auto-commit" method. Refer to this article for more explanation.

Q7. What is JPQL?

JPQL is Java Persistence Query Language defined in JPA specification. It is used to create queries against entities to store in a relational database. JPQL is developed based on SQL syntax. But it won’t affect the database directly.
JPQL can retrieve information or data using SELECT clause, can do bulk updates using UPDATE clause and DELETE clause. EntityManager.createQuery() API will support for querying language.
JPQL syntax is very similar to the syntax of SQL. Having SQL like syntax is an advantage because SQL is a simple structured query language and many developers are using it in applications. SQL works directly against relational database tables, records and fields, whereas JPQL works with Java classes and instances.

Q8. What is indexing in databases?

Indexing is used to optimize the performance of a database by minimizing the number of disk accesses required when a query is processed.
The index is a type of data structure. It is used to locate and access the data in a database table quickly.
Indexes can be created using some database columns.
The first column of the database is the search key that contains a copy of the primary key or candidate key of the table. The values of the primary key are stored in sorted order so that the corresponding data can be accessed easily.
The second column of the database is the data reference. It contains a set of pointers holding the address of the disk block where the value of the particular key can be found.
See this article for a detailed explanation.

Q9. When can we use the HAVING and GROUP BY clause in SQL?

  • HAVING Clause utilized in combination with GROUP BY Clause.
  • Having can be used without groupby clause,in aggregate function,in that case it behaves like where clause.
  • groupby can be used without having clause with the select statement.
  • HAVING Clause restricts the data on the group records rather than individual records.
  • WHERE and HAVING can be used in a single query.
Q10. Where we can use GROUP BY with WHERE clause?

  • GROUP BY clause is used with the SELECT statement.
  • In the query, GROUP BY clause is placed after the WHERE clause.
  • In the query, GROUP BY clause is placed before ORDER BY clause if used any.
Q11. views vs procedures?

Stored Procedure: Stored procedures are precompiled database queries that improve the security, efficiency, and usability of database client/server applications. Developers specify a stored procedure in terms of input and output variables. They then compile the code on the database platform and make it available to application developers for use in other environments, such as web applications. All of the major database platforms, including Oracle, SQL Server, and MySQL support stored procedures. The major benefits of this technology are the substantial performance gains from precompiled execution, the reduction of client/server traffic, development efficiency gains from code reuse and abstraction, and the security controls inherent in granting users permissions on specific stored procedures instead of the underlying database tables.

Views: Database views allow you to create "virtual tables" that are generated on the fly when they are accessed. A view is stored on the database server as an SQL statement that pulls data from one or more tables and (optionally) performs transformations on that data. Users may then query the view just as they would any real database table. Views are often used to alleviate security concerns by providing users with access to a certain view of a database table without providing access to the underlying table itself.




Q12. What is a composite key in databases?

A composite key in a table is a combination of more than one column that can identify a row of that table uniquely. 

Q13.