Java JDBC

Last Updated :
Discuss
Comments

Question 1

What is the main purpose of JDBC in Java?

  • A

    Manage user authentication

  • B

    Connect and interact with databases

  • C

    Enhance file operations

  • D

    Optimize memory usage

Question 2

Which JDBC driver type translates JDBC calls into database-specific calls without using native libraries?

  • A

    Type-1


  • B

    Type-2

  • C

    Type-3

  • D

    Type-4

Question 3

Before executing any SQL query, which method must be called to establish a database connection?


  • A

    DriverManager.registerDriver()

  • B

    Connection.prepare()

  • C

    DriverManager.getConnection()

  • D

    DriverManager.createConnection()

Question 4

Which interface represents a SQL database connection in JDBC?


  • A

    ResultSet

  • B

    Statement

  • C

    Connection

  • D

    DriverManager

Question 5

Which JDBC statement is used when you need to execute dynamic SQL with different parameters at runtime?

  • A

    Statement

  • B

    PreparedStatement

  • C

    CallableStatement

  • D

    ResultSet

Question 6

What exception does JDBC primarily throw when something goes wrong?


  • A

    IOException

  • B

    SQLException

  • C

    DatabaseException


  • D

    JDBCException


Question 7

Identify the correct order to perform basic JDBC operations:

  • A

    Connect → Create Statement → Execute Query → Close

  • B

    Create Statement → Connect → Execute Query → Close

  • C

    Execute Query → Connect → Create Statement → Close

  • D

    Connect → Execute Query → Create Statement → Close


Question 8

Given the snippet below, what will it print if the database is connected successfully?

Java
Connection con = DriverManager.getConnection(dbURL, user, pass);
if (con != null) {
    System.out.println("Connection Successful");
}
  • A

    Connection Failed

  • B

    Exception Thrown

  • C

    Connection Successful

  • D

    No Output


Question 9

Which JDBC driver type uses an intermediate server to communicate with the database?


  • A

    Type-1

  • B

    Type-2

  • C

    Type-3

  • D

    Type-4

Question 10

Which of the following is true for CallableStatement?

  • A

    It executes simple SQL queries only

  • B

    It is used to call stored procedures in a database

  • C

    It can only be used for SELECT operations

  • D

    It is used to manage JDBC drivers

There are 10 questions to complete.

Take a part in the ongoing discussion