Multiple Choice Questions on JDBC in JavaJDBC is an API (Application Programming Interface) that helps a programmer to write a Java program to connect to a database, retrieve the data from the database, and perform various operations on the data in a Java program. As it is an important topic, the questions related to JDBC frequently asked in Java interviews and competitive exams. So, in this section, we have collected some multiple-choice questions based on JDBC that are important from the perspective of different competitive exams and interviews. 1) What are the major components of the JDBC?
Answer: a Explanation:
2) Select the packages in which JDBC classes are defined?
Answer: d Explanation: JDBC API is divided into two packages i.e. java.sql and javax.sql. We have to import these packages to use classes and interfaces in our application. 3) Thin driver is also known as?
Answer: c Explanation: The JDBC thin driver is a pure Java driver. It is also known as Type-4 Driver. It is platform-independent so it does not require any additional Oracle software on the client-side. It communicates with the server using SQL *Net to access Oracle Database. 4) What is the correct sequence to create a database connection? i. Import JDBC packages. ii. Open a connection to the database. iii. Load and register the JDBC driver. iv. Execute the statement object and return a query resultset. v. Create a statement object to perform a query. vi. Close the resultset and statement objects. vii. Process the resultset. viii. Close the connection.
Answer: b Explanation: To create a database connection in Java, we must follow the sequence given below:
5) Which of the following method is used to perform DML statements in JDBC?
Answer: c Explanation: We use the executeUpdate() method for DML SQL queries that change data in the database, such as INSERT, UPDATE, and DELETE which do not return a resultset. 6) How many transaction isolation levels provide the JDBC through the Connection interface?
Answer: b Explanation: The following table defines transaction isolation levels.
7) Which of the following method is static and synchronized in JDBC API?
Answer: A Explanation: A Java application using the JDBC API establishes a connection to a database by obtaining a Connection object. The standard way to obtain a Connection object is to call the method DriverManager.getConnection() method that accepts a String contains the database connection URL. It is a static and synchronized method. 8) Which methods are required to load a database driver in JDBC?
Answer: d Explanation: There are two ways to load a database driver in JDBC:
9) Parameterized queries can be executed by?
Answer: b Explanation: The PreparedStatement interface extends the Statement interface. It represents a precompiled SQL statement that can be executed multiple times. It accepts parameterized SQL quires. We can pass 0 or more parameters to this query. 10) Which of the following is not a valid statement in JDBC?
Answer: c Explanation:
11) Identify the isolation level that prevents the dirty in the JDBC Connection class?
Answer: b Explanation: The isolation level TRANSACTION_READ_COMMITTED prevents the dirty read but non-repeatable reads and phantom reads can occur. 12) What does setAutoCommit(false) do?
Answer: b Explanation: The way to allow two or more statements to be grouped into a transaction is to disable the auto-commit mode. After the auto-commit mode is disabled, no SQL statements are committed until we call the commit() method explicitly. 13) Stored procedure can be called by using the ????..?
Answer: b Explanation: The stored procedure is a database program that can be utilized to perform CRUD tasks with the table. We can call these procedures by using the Statement Interface. It provides methods to execute queries with the database. 14) What should be the correct order to close the database resource?What should be the correct order to close the database resource?
Answer: d Explanation: The golden rule to JDBC connections and statements is to close in the reverse order of initiation or opening. In addition, the ResultSet is dependant on the execution of the Statement and the Statement is dependant on the Connection instance. Hence, the closing should occur in that order (ResultSet, Statement, and then Connection). 15) A good way to debug JDBC-related problems is to enable???..?
Answer: a Explanation: The JDBC Driver supports both DriverManager and DataSource tracing as documented in the JDBC 3.0 API specification. Trace information consists of JDBC API method entry and exit points with the corresponding parameter and returns values. DriverManager.setLogWriter method to send trace messages to a PrintWriter. The trace output contains a detailed listing of the JDBC activity. 16) Which JDBC driver can be used in servlet and applet both?
Answer: d Explanation: Type 3 driver follows the three-tier approach which is used to access the databases. The JDBC clients use standard network sockets to communicate with a middleware application server. In a Type 4 driver, a pure Java-based driver that communicates directly with the vendor's database through a socket connection. 17) JDBC-ODBC driver is also known as?
Answer: c Explanation: Type 1 driver is also known as the JDBC-ODBC bridge driver. It is a database driver implementation that employs the ODBC driver to connect to the database. The driver converts JDBC method calls into ODBC function calls. 18) Which of the following driver is the fastest one?
Answer: d Explanation: JDBC Net pure Java driver (Type 4) is the fastest driver because it converts the JDBC calls into vendor-specific protocol calls and it directly interacts with the database. 19) Which of the following is not a type of ResultSet object?
Answer: b Explanation: There are three types of ResultSet object:
Based on the concurrency there are two types of ResultSet object.
20) What is JDBC Savepoint?
Answer: a Explanation: JDBC Savepoint helps us in creating checkpoints in a transaction and we can rollback to that particular checkpoint. 21) How many stages are used by Java programmers while using JDBC in their programs?
Answer: d Explanation: There are following stages in a JDBC program:
22) Which of the following is the correct to register a JdbcOdbcDriver?
Answer: a Explanation: By creating an object to the driver class of the driver software, we can register the driver. To register the JdbcOdbcDriver of the sun microsystems, we can create an object to the driver class JdbcOdbcDriver, as follows: sun.jdbc.odbc.JdbcOdbcDriver obj = new sun.jdbc.odbc.JdbcOdbcDriver(); 23) How many ways to register a driver?
Answer: c Explanation: There are four ways to register a driver: 1. By creating an object of the Driver For example: sun.jdbc.odbc.JdbcOdbcDriver obj = new sun.jdbc.odbc.JdbcOdbcDriver(); 2. By sending the driver class object to the registerDriver() method of the DriverManager class. For example: DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver()); 3. By sending the driver class name directly to the forName() For example: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 4. By using the getProperty() method of the System class. For example: String dname = System.getProperty("driver"); Class.forName(dname); If you are using the above method to register the driver, we should have to specify the driver's name at the time of running the program. The getProperty() method receives the driver name and stores the driver name in dname. We use the following command to provide the driver name at run time: c:\> java -Ddriver = driverclassname Programname For example: c:\> java -Ddriver = sun.jdbc.odbc.JdbcOdbcDriver MyProgram 24) Identify the DSN in the following statement:
Answer: d Explanation: Data Source Name (DSN) is a name given to the database to identify it in the Java program. The DSN is linked with the actual location of the database. 25) Which statement is correct if we want to connect the Oracle database using the thin driver provided by Oracle Corp.?
Answer: a Explanation: We use the following statement to connect Oracle database using the thin driver. DriverManager.getConnection("jdbc::thin@localhost:1521:oracle", "scott", "tiger"); 26) What are the types of ResultSet in JDBC?
Answer: d Explanation: JDBC provides only two types of ResultSets: Forward and Scrollable ResultSet. 27) What is blob in the following statement?
Answer: c Explanation: SQL offers BLOB (Binary Large OBject) data type to store image files like .gif or .jpg or jpeg into the database table. 28) Which data type is used to store files in the database table?
Answer: b Explanation: To store a large volume of data such as text file into a table, we use CLOB (Character Large OBject) data type of SQL. 29) DatabaseMetaData interface is used to get?????..?
Answer: a Explanation: DatabaseMetaData is an interface that is used to get Comprehensive information about the database as a whole. It is implemented by driver vendors to let users know the capabilities of a DBMS in combination with the JDBC driver that is used with it. 30) Which of the following driver converts the JDBC calls into database-specific calls?
Answer: b Explanation: Type 2 driver converts JDBC calls into database-specific calls with the help of vendor database library. It directly communicates with the database server. 31) Are ResultSets updateable?
Answer: b Explanation: By default, a ResultSet object is not updatable and its cursor moves only in the forward direction. If we want to create an updateable ResultSet object, either we can use ResultSet.TYPE_SCROLL_INSENSITIVE or the ResultSet.TYPE_SCROLL_SENSITIVE type, which moves the cursor forward and backward relative to the current position. 32) Which of the following interface provides the commit() and rollback() methods?
Answer: c Explanation: The connection interface provides the commit() and rollback() method. The commit() method makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by this Connection object. The rollback() method undoes all changes made in the current transaction and releases any database locks currently held by this Connection object. 33) How many statement objects can be created using a Connection?
Answer: d Explanation: Multiple statements can be created and used on the same connection, but only one resultset at once can be created and used on the same statement. 34) JDBC API supports____________ and __________ architecture model for accessing the database.
Answer: c Explanation: The JDBC API supports both two-tier and three-tier processing models for database access. In the two-tier model, a Java application talks directly to the data source. In the three-tier model, commands are sent to a "middle tier" of services, which then sends the commands to the data source. 35) Which statement(s) is/ are true about transactions? i. A transaction is a set of one or more SQL statements that make up a logical unit of work. ii. A transaction ends with either a commit or a rollback, depending on whether there are any problems with data consistency or data concurrency. iii. A lock is a mechanism that allows two transactions from manipulating the same data at the same time. iv. To avoid conflicts during a transaction, a DBMS uses locks, mechanisms for blocking access by others to the data that is being accessed by the transaction.
Answer: c Explanation: The statements i, ii, and iv are true about transactions but iii is not because the lock mechanism prohibits two transactions from manipulating the same data at the same time. Next Topic#
|
Python tutorial provides basic and advanced concepts of Python.
Vue.js is an open-source progressive JavaScript framework
HTML refers to Hypertext Markup Language. HTML is the gateway ...
Java is an object-oriented, class-based computer-programming language.
PHP is an open-source,interpreted scripting language.
Spring is a lightweight framework.Spring framework makes ...
JavaScript is an scripting language which is lightweight and cross-platform.
CSS refers to Cascading Style Sheets...
jQuery is a small and lightweight JavaScript library. jQuery ...
SQL is used to perform operations on the records stored in the database.
C programming is considered as the base for other programming languages.
JavaScript is an scripting language which is lightweight and cross-platform.
Vue.js is an open-source progressive JavaScript framework
ReactJS is a declarative, efficient, and flexible JavaScript library.
jQuery is a small and lightweight JavaScript library. jQuery ...
Node.js is a cross-platform environment and library for running JavaScript app...
TypeScript is a strongly typed superset of JavaScript which compiles to plain JavaScript.
Angular JS is an open source JavaScript framework by Google to build web app...
JSON is lightweight data-interchange format.
AJAX is an acronym for Asynchronous JavaScript and XML.
ES6 or ECMAScript 6 is a scripting language specification ...
Angular 7 is completely based on components.
jQuery UI is a set of user interface interactions built on jQuery...
Python tutorial provides basic and advanced concepts of Python.
Java is an object-oriented, class-based computer-programming language.
Node.js is a cross-platform environment and library for running JavaScript app...
PHP is an open-source,interpreted scripting language.
Go is a programming language which is developed by Google...
C programming is considered as the base for other programming languages.
C++ is an object-oriented programming language. It is an extension to C programming.
C# is a programming language of .Net Framework.
Ruby is an open-source and fully object-oriented programming language.
JSP technology is used to create web application just like Servlet technology.
The JSTL represents a set of tags to simplify the JSP development.
ASP.NET is a web framework designed and developed by Microsoft.
Perl is a cross-platform environment and library for running JavaScript...
Scala is an object-oriented and functional programming language.
VBA stands for Visual Basic for Applications.
Spring is a lightweight framework.Spring framework makes ...
Spring Boot is a Spring module that provides the RAD feature...
Django is a Web Application Framework which is used to develop web applications.
Servlet technology is robust and scalable because of java language.
The Struts 2 framework is used to develop MVC based web applications.
Hibernate is an open source, lightweight, ORM tool.
Solr is a scalable, ready-to-deploy enterprise search engine.
SQL is used to perform operations on the records stored in the database.
MySQL is a relational database management system based...
Oracle is a relational database management system.
SQL Server is software developed by Microsoft.
PostgreSQL is an ORDBMS.
DB2 is a database server developed by IBM.
Redis is a No SQL database which works on the concept of key-value pair.
SQLite is embedded relational database management system.
MongoDB is a No SQL database. It is an document-oriented database...
Memcached is a free, distributed memory object caching system.
Hibernate is an open source, lightweight, ORM tool.
PL/SQL is a block structured language that can have multiple blocks in it.
DBMS Tutorial is software that is used to manage the database.
Spark is a unified analytics engine for large-scale data processing...
IntelliJ IDEA is an IDE for Java Developers which is developed by...
Git is a modern and widely used distributed version control system in the world.
GitHub is an immense platform for code hosting.
SVN is an open-source centralized version control system.
Maven is a powerful project management tool that is based on POM.
Jsoup is a java html parser.
UML is a general-purpose, graphical modeling language.
RESTful Web Services are REST Architecture based Web Services.
Postman is one testing tools which is used for API testing.
JMeter is to analyze the performance of web application.
Jenkins builds and tests our software projects.
SEO stands for Search Engine Optimization.
MATLAB is a software package for mathematical computation, visualization...
Unity is an engine for creating games on multiple platforms.
Hadoop is an open source framework.
Pig is a high-level data flow platform for executing Map Reduce programs of Hadoop.
Spark is a unified analytics engine for large-scale data processing...
Spring Cloud is a framework for building robust cloud applications.
Spring Boot is a Spring module that provides the RAD feature...
AI is one of the fascinating and universal fields of Computer.
Cloud computing is a virtualization-based technology.
AWS stands for Amazon Web Services which uses distributed IT...
Microsoft Azure is a cloud computing platform...
IoT stands for Internet of Things...
Spring Cloud is a framework for building robust cloud applications.
Email:jjw.quan@gmail.com