OCP Flashcards – 11. Building Database Applications with JDBC

OCP Exam Objective 11 – Building Database Applications with JDBC

Flashcard OCP.11.Building.Database.Applications.with.JDBC.001

What is JDBC?

Click here to view answer
JDBC (Java Database Connectivity) APIs provided by Java are meant for programmatic access to DataBase Management Systems (DBMSs).

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.002

What does the java.sql.Connection interface do?

Click here to view answer
It provides a channel through which the application and the database communicate.

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.003

How would you establish a connection to a DB?

Click here to view answer
By calling the DriverManager#getConnection() method, which takes three arguments: the URL string, username string, and password string. There’s also an overloaded version that takes just the URL string.

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.004

What is the local connection string syntax for the Java DB Network Client Driver?

Click here to view answer
For example:
jdbc:derby://localhost:port/databaseName

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.005

What is the connection string syntax for the Java DB Embedded Driver?

Click here to view answer
For example:
jdbc:derby:databaseName

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.006

How would you load the JDBC driver prior to JDBC 4.0?

Click here to view answer
Prior to JDBC 4.0, you would have to explicitly load the JDBC driver by calling Class.forName().

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.007

How does JDBC 4 differ from previous versions when it establishes a database connection?

Click here to view answer
JDBC 4 and above automatically loads suitable drivers based on the database connection URL.

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.008

What method would you use to establish a database connection using JDBC 4 drivers?

Click here to view answer
DriverManager.getConnection()

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.009

Does the java.sql.Connection interface extend AutoCloseable?

Click here to view answer
Yes, it does.

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.010

When is a Connection object closed if it is declared in a try-with-resources statement?

Click here to view answer
After the try block runs

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.011

What interfaces are supported by JDBC for querying and updating?

Click here to view answer
Statement and Resultset.

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.012

What is the java.sql.Statement interface used for?

Click here to view answer
The object of this type is used for executing an SQL statement on the connected database and receiving results from the DB.

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.013

How many ResultSet objects per Statement can be open at the same time?

Click here to view answer
By default, only one. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects.

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.014

What happens to the currently open ResultSet object after execution of a Statement method?

Click here to view answer
All execution methods in the Statement interface implicitly close a current ResultSet object of the statement if an open one exists.

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.015

What is the java.sql.ResultSet interface used for?

Click here to view answer
It’s a table of data representing the results returned after querying the DB. The ResultSet object maintains a cursor pointing to the current row. Initially, the cursor is set to just before the first row.

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.016

What does the ResultSet‘s column index start from?

Click here to view answer
The column index in the ResultSet object starts from 1 rather than from 0.

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.017

Which ResultSet method should be invoked before accessing the first row?

Click here to view answer
next()

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.018

Which ResultSet method moves the cursor forward one row?

Click here to view answer
next()

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.019

What should be done after modifying the row contents in a ResultSet?

Click here to view answer
You would need to call updateRow() otherwise changes made to the ResultSet object are lost.

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.020

Which field indicates that a ResultSet object supports updates?

Click here to view answer
CONCUR_UPDATABLE

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.021

Which Statement method should be invoked to execute SELECT queries?

Click here to view answer
executeQuery()

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.022

Which two fields will create a scrollable ResultSet object?

Click here to view answer
TYPE_SCROLL_INSENSITIVE and TYPE_SCROLL_SENSITIVE

 

Flashcard OCP.11.Building.Database.Applications.with.JDBC.023

Which field indicates a scrollable ResultSet object that reflects changes to the underlying data source while it is open?

Click here to view answer
TYPE_SCROLL_SENSITIVE

Leave Comment

Your email address will not be published.