23 JDBC interview questions and answers
jdbc interview questions
Welcome to JDBC Interview Questions and Answers. JDBC API is used to connect to relational databases and run SQL queries from Java Programs. In the last few articles, we learned about JDBC API and its important features. This article is aimed to provide some of the important JDBC Interview Questions with Answers to help you in Java interview.
jdbc interview questions
As a best practice, we must close the resultset, the statement and the connection. If the connection is coming from a pool, on closure, the connection is sent back to the pool for reuse. We are doing this in the finally{} block, because if any exception occurs, then we still get the chance to close this.
jdbc interview questions
When a connection is created, it is in auto-commit mode. This means that each individual SQL statement is treated as a transaction and will be automatically committed right after it is executed. By setting auto-commit to false no SQL statements will be committed until you explicitly call the commit method. Why will you set auto commit mode to false?
A transaction is a logical unit of work. To complete a logical unit of work, several actions may need to be taken against a database. Transactions are used to provide data integrity, correct application semantics, and a consistent view of data during concurrent access. How will you insert multiple rows into a database in a single transaction?
Prepared statements offer better performance, as they are pre-compiled. Prepared statements reuse the same execution plan for different arguments rather than creating a new execution plan every time. Prepared statements use bind arguments, which are sent to the database engine. This allows mapping different requests with same prepared statement but different arguments to execute the same execution plan. Prepared statements are more secure because they use bind variables, which can prevent SQL injection attack. How do you register a driver?There are 2 approaches for registering the Driver
In typical database transactions, say one transaction reads and changes the value while the second transaction reads the value before committing or rolling back by the first transaction. This reading process is called as dirty read. Because there is always a chance that the first transaction might rollback the change which causes the second transaction reads an invalid value. Which isolation level prevents dirty read in JDBC, connection class?
If you use an application server like WebLogic, WebSphere, jBoss, Tomcat. , then your application server provides the facilities to configure for connection pooling. If you are not using an application server then components like Apache Commons DBCP Component can be used. Out of byte[] or a java.sql.Blob, which has best performance when used to manipulate data from database?
jdbc interview questions
Java database connectivity (JDBC) is an API that enables Java programs to execute SQL statements. If you are attending an interview related to JDBC, you need to gain knowledge on different aspects of the subject. Every job seeker is unsure about the JDBC interview questions and answers he/ she is going to encounter during the interview process. Gaining some information on the same would make getting placed an easy job for the job seeker. Let wisdomjobs.com help you in this regard. Reach the portal to know various job interview questions and answers that you are going to encounter during the process and give a thorough preparation in this regard to win the competitions. A well-researched set of questions framed here will give you the exposure to the skill set the interviewer is looking for to hire you for the job.