Java 5TH Chapter - 22517

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

AJP – 22517

CHAPTER 5 ~ INTERACTING WITH DATABASE

3 Abbreviate the term DSN


Data Source Name 17 createStatement() method without any
parameter is used to create a statement with
__________
6 API which controls access to the row result a forward only and read only ResultSet
of a given Statement and holds data retrieved
from a database after you execute an SQL
query using Statement objects.
18 Database meta data are retrieved through
java.sql.ResultSet _____
a PreparedStatement object
8 Backbone of JDBC Architecture is ____
Driver Manager 23 execution of delete SQL query in JDBC,
............. method must be used.
executeUpdate()
10 Callable Statement used to --------
calling procedure
25 For execution of INSERT SQL query in
JDBC, ............. method must be used.
11 Callable statement object in JDBC is used executeUpdate()
to execute a call to
stored procedure
28 getConnection() method of which class
DriverManager
13 Choose the correct syntax for
getConnection() method
public static Connection 33 How many steps are used to connect any
getConnection(String url, String name, java application with the database using
String password) throws SQLException JDBC?
5
14
Class.forName("___________________")
51 Native API converts
sun.jdbc.odbc.JdbcOdbcDriver __________________into the
_______________________ used by DBMS.
JDBC API, Native API calls
16 Connection object can be initialized using
the _______ method of the DriverManager
Class.
getConnection()
AJP – 22517
CHAPTER 5 ~ INTERACTING WITH DATABASE

52 Native – protocol pure Java converts 91 Type II JDBC driver is also known as __
……….. in to the ………… used by DBMSs
directly. Native API partly Java driver

JDBC calls, network protocol


92 Type IV JDBC driver is also known as __

55 ODBC minimum SQL grammar contains Native Protocol Pure-Java Driver

INSERT, UPDATE ,DELETE ONLY


104 Which driver is needed to connect to
Microsoft database?
66 The .................. object provides you with
methods to access data from the table. JDBC-ODBC Bridge Driver

ResultSet
107 Which interface is important from
java.sql package in JDBC?
67 The ...................... method sets the query
parameters of the PreparedStatement Object. Connection

setString()
110 Which is default ResultSet type

73 The First task in JDBC is _________ TYPE_FORWARD_ONLY

register a driver
111 Which is not a type of JDBC driver

77 The parameters of the PreparedStatement JDBC-Native pure java


object are ...................... when the user clicks
on the Query button.
113 Which JDBC driver Type (s) can be used
Initialized in either applet or servelt code?
Both Type 3 and Type 4
89 Type 1 driver is also known as
JDBC-ODBC Bridge Driver 115 Which JDBC driver Types are used for
over communications networks?

90 Type 3 driver is also known as_________ Both Type 3 and Type 4

JDBC-net Pure Java


117 Which method is used to obtain count of
total rows of ResultSet
getRow
AJP – 22517
CHAPTER 5 ~ INTERACTING WITH DATABASE

121 Which method of class is used to register 155 __________ method of DriverManager
& dynamically load the driver class? class is used to create connection with
database. getConnection()
forName()

160 '?' symbol is used for ________


124 Which of the following invokes
functions in sql ? parameter in prepared statement
Callable statements
163 A benefit of the three-tier architecture is
which of the following?
129 Which of the following method is
method is used to load and register driver ? New modules can be built to support specific
business needs.
Class.forName("sun.jdbc.odbc.JdbcOdbcDri
ver")
164 afterLast() method return_________
136 Which of the following translates the Moves cursor to the end of resultset that is
socket information in call format required by after last row.
the DBMS.
Middleware Application Server
174 boolean execute() method returns
Multiple results
142 Which statement is static and
synchronized in JDBC.
getConnection() 175 By using which interface one can store
images in the database in java ?
PreparedStatement interface
146 Which type of driver is unqiue in JDBC?
JDBC-Native API
281 createStatement( ) method
returns_____________________
151 ________ is an interface by which Statement object
application programs can access and process
SQL databases in a DBMS-independent
manner. 282 database programming using Java throws
ODBC which exception?
SQLException
AJP – 22517
CHAPTER 5 ~ INTERACTING WITH DATABASE

283 DatabaseMetaData are retrieved through 334 In DriverManager class which method is
____________. used to establish the connection with the
specified url?
Connection object
public static Connection
getConnection(String url)
287 DriverManager class does not provides
methods for ___________________
354 kind of driver converts JDBC calls on
Executing sql statement and retrieving results client API for Oracle, cybase, Informix, DB2,
or other DBMS is known as__________

308 getConnection() method have which Native API partly-Java driver


parameters: _____________
URL -JdbclOdbc:DSN ,String Username, 355 Method which drops the driver from the
String Password list of drivers registered in the DriveManager
class.

309 getConnection() method of deregisterDriver(Driver driver)


DriverManager returns
__________________________
370 Permission class is part
Connection Object of_________package
java.security.permission
310 getResultSet() method belongs to ____
Statement interface 373 Prepared Statement interface creates an
object that represents a________________

318 Identify the correct code to retrive values Precompiled SQL Statement
from database
Statement st=con.createStatement(); 374 PreparedStatement interface
ResultSet rs=st.executeQuery(); extends____________________ interface
Statement
320 Identify wrong type of ResultSet
ResultSet.TYPE_BACKWORD_ONLY 375 PreparedStatement object in JDBC is
used to execute
____________________quiries
322 If ___________is set to true,then a
commit is implicitly applied after the Parameterized
execution of every SQL statement.
AutoCommit
AJP – 22517
CHAPTER 5 ~ INTERACTING WITH DATABASE

377 PrepareStatement() method is of 449 What does the following code do?
____________________ interface smt=con.createStatement();
Connection A Statement object is created to send sql
commands to the database

378 Provides information about occurance of


event____________ 453 What happens if you call deleteRow() on
a ResultSet object?
javax.sql.ConnectionEvent
The row you are positioned on is deleted form
the ResultSet and from the database.
386 select correct method of statement
interface
454 What happens if you call the method
public ResultSet executeQuery(String close() on a ResultSet object?
sql)throws SQLException
the database and JDBC resources are released

393 Select the correct option that can be used


to create a result set in which the cursor can 467 What is the disadvantage of Type-4
move in both the directions. Native-Protocol Driver?
TYPE_SCROLL_SENSITIVE At client side, a separate driver is needed for
each database.

403 Set XXX() method binds values to the


parameters. Where XXX represents 463 what is Native Protocol, Pure Java
Driver?
Data Type
This type of driver, written entirely in Java,
communicates directly with the database.
404 Statement interface is used for ____
sending SQL queries to the database 485 What is the use of Statement interface?
Statement interface provides methods to
414 The JDBC-ODBC Bridge supports execute quries with database.
multiple concurrent open statements per
connection?
486 What is, in terms of JDBC, a
One DataSource?
A DataSource is a factory of connections to a
424 The __________method sets the query physical data source
parameters of the PreparedStatement Object.
setString()
AJP – 22517
CHAPTER 5 ~ INTERACTING WITH DATABASE

488 What MySQL property is used to create 537 Which JDBC driver Type(s) can you use
a surrogate key in MySQL? in a three-tier architecture and if the Web
server and the DBMS are running on the
AUTO_INCREMENT same machine?
All of Type 1, Type 2, Type 3 and Type 4
512 When the message "No suitable drivers
found" is displayed?
538 Which JDBC driver Type(s) is (are) the
if JDBC database URL passed is not JDBC-ODBC bridge?
constructed properly.
Type-1

513 When using ODBC, which of the


following processes ODBC requests and 539 Which JDBC driver Types are for use
submits specific SQL statements to a given over communications networks?
type of data source?
Both Type 3 and Type 4
Driver.

540 Which kind of driver converts JDBC


517 Which class has traditionally been the calls into calls on the client API for Oracle,
backbone of the JDBC architecure ? Sybase, Informix, IBM DB2, or other
DBMS?
the JDBC driver manager
B. Native -API partly-java driver

518 Which interface allows storing results of


query. 548 Which object provides
DatabaseMetaData object?
Resultset
Connection

535 Which JDBC driver maps the JDBC calls


to the native method calls, which are passed 549 Which object provides
to the local native Call Level Interface (CLI)? ResultSetMetaData object?
Native-API-Partly-Java driver ResultSet
554 Which of the following describes the
correct url String format of getConnection()
536 Which JDBC driver Type(s) can be used method.
in either applet or servlet code?
protocol,subprotocol,datasource name
Both Type 3 and Type 4
AJP – 22517
CHAPTER 5 ~ INTERACTING WITH DATABASE

555 Which of the following invokes stored 599 ____type of driver is very flexible and
procedures in sql? need not code installation on the client
machine
callable statements
Type 3-JDBC-Net Pure java

558 Which of the following is the correct


syntax of executeQuery() method? 600 ______moves the cursor to the specified
row
ResultSet executeQuery(String str)
public boolean absolute(int row)

567 Which of the following statement is false


as Type 4 driver is concern: 601 ________ is an open source DBMS
product that runs on UNIX, Linux and
Type 4 drivers can not be used with Windows.
NetScape.
MySQL

583 Which statement is static and


synchronized in JDBC API? 602 __________is the key
to__________with respected to RDBMS?
getConnection()
Serialization,persistence

584 Which Statement is used to execute


Dynamic Query 603 ___________Calls get converted into
native c or c++ API calls
PreparedStatemen
JDBC API

592 Which type of driver converts JDBC


calls into the network protocol used by the 604 _______________ interface allows
database management system directly? stroing results of query?
Type 4 driver Resultset

593 Which type of Statement can execute 605 ________________ method of


parameterized queries? Connection interface is used to create the
Statement object.
PreparedStatement
createStatement()
AJP – 22517
CHAPTER 5 ~ INTERACTING WITH DATABASE

606 ________________ method of 608 _______________________Returns a


DriverManager is used to establish ResultSetMetaData object describing the
connection with the database. ResultSet.
getConnection() getMetaData

607 ____________________ Returns the 609 …………………… can not directly


current row number, with the first row communicate with database to submit data
starting at 1 & retrive the result.
getRow() JDBC

610 Which of the following statements loads the JDBC-ODBC driver?


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
AJP – 22517
CHAPTER 5 ~ INTERACTING WITH DATABASE

• ODBC stands for Open Database Connectivity. It is basically API i.e. Application
Programming Interface.
• Import.java.sql.* package is used.
• JDBC stands for Java DataBase Connectivity. JDBC is nothing but an API (i.e.
Application Programming Interface).
• JDBC Architecture
- Two tier : Java application can directly communicate with database using JDBC
driver API.

- Three tier: HTML browser will send command to java application to communicate
with database using JDBC driver API.
AJP – 22517
CHAPTER 5 ~ INTERACTING WITH DATABASE

• JDBC DRIVERS:
1) Types 1: JDBC – ODBC Bridge, it can have access to any database possible

2) Type 2: Native API / Partly Java Driver


- It translates all JDBC calls into database specific calls.
- This type of driver directly communicates with the database server

3) Type 3: All JAVA/ Net Protocol driver for accessing middleware server.
- all the JDBC calls are passed through the network to the middle-ware server
- This is also known as as JDBC net - pure Java driver.

4) Type 4: All JAVA / Native-Protocol Pure driver


- This driver converts JDBC calls into Network Protocols.
- It is also referred as Native Protocol - Pure Java Driver.

• Steps to connect to a database.


- Loading the driver
- Making the connection with database.
- Executing the SQL statements.
- Process the necessary results.

• Driver Interface.
- The JDBC API is a set of classes, interfaces and exceptions used for establishing
connection with data source.
- This JDBC API is defined in the java.sql and javax.sql packages.
- It Contains following classes.

1) Driver Manager Class


- This class is used to make a connection with database. It loads JDBC drivers.
- For this the following statement is used.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;

2) Connection Interface
- This interface connects to the data source, creating a Statement instance.
- To connect, use DriverManager.getConnection() method from JDBC, and write a
statement in Java.
AJP – 22517
CHAPTER 5 ~ INTERACTING WITH DATABASE

3) Statement Interface
- It is used to execute static SQL statements.
- It cannot accept Parameters.

- Prepared Statement is used to execute SQL statement multiple times.


- The PreparedStatement interface can be created by calling PrepareStatement()
method.
- The prepareStatement() is available in java.sql.Connection interface.
- The Callable statement is used when we want to access database stored procedures.
- The CallableStatement object is used.
CallableStatement callableStatement = connection.prepareCall("{call myprocedure(?, ?)}");

4) Resultset Interface
- It is used to access database tables.
- The rows are retrieved using resultSet object.
- It maintains a cursor to the current row of data. Initially it is positioned before the
first row.
- The ResultSet object can be created using executeQuery() method.
- Navigating methods
AJP – 22517
CHAPTER 5 ~ INTERACTING WITH DATABASE
- Methods for reading results using Resultset.

- Methods for updating resultset.

You might also like