Ajp MCQ Chapter 5
Ajp MCQ Chapter 5
3) Which of the following classes/interface allows you to send SQL statement to database for
execution and read the result:
a) java.sql.Statement
b) java.sql.PreparedStatement
c) java.sql.ResultSet
d) All of the above
a)This class provides the functionality necessary for managing one or more database
drivers.
b)This is an interface that abstracts the vendor specific connection protocol
c)This class is used to discover properties required to obtain the connection
d)This interface abstracts most of the interaction with the database
8) Which interface lets you execute SQL statements over the underlying connection and
access the results?
a) java.sql.Statement
b) java.sql.PreparedStatement
c) java.sql.ResultSet
d)java.sql.CallableStatement
10) The java.sql package provides several Java _______ class that correspond to some of the
SQL types.
a)Connection Management
b)Database Access
c)Data Types
d)Both (a) and (b)
13) Which of the following comes under SQL Exception and Warnings?
a) java.sql.SQLexception
b) java.sql.SQLWarning
c) java.sql.DataTruncation
d) Both (b) and (c)
c) Both a and b
d) None of the above
b) sun.jdbc.odbc
c) java.jdbcodbc
d) None of the above
18) Which of the following is JDBC version was released with Java EE 6
a) JDBC 2.0
b) JDBC 3.0
c) JDBC 4.0
d) JDBC 4.1
19) JDBC API provides __________ and ___________ to handle database specific call from
users.
a) methods, functions
b) classes, interfaces
c) packages, classes
d) interfaces, packages
c) DriverManager
d) ResultSet
21) _____________ refers to the bridge driver (JDBC-ODBC Bridge)
a. Type-1 Driver
b. Type-2 Driver
c. Type-3 Driver
d. Type-4 Driver
22) _____________ refers to a partly java and partly native code driver
a. Type-1 Driver
b. Type-2 Driver
c. Type-3 Driver
d. Type-4 Driver
23) _____________ refers to pure Java Driver that uses a middleware driver to connect to a
database
a. Type-1 Driver
b. Type-2 Driver
c. Type-3 Driver
d. Type-4 Driver
24) _____________ refers to pure Java Driver which is directly connected to a database
a. Type-1 Driver
b. Type-2 Driver
c. Type-3 Driver
d. Type-4 Driver
26) Which of the following is not the component of 3-tier architecture of JDBC
a. DataSource Object
b. Java Application
c. Java API
d. Database
27) The javax.sql provides ................................ implementations which are used in building
server-side applications.
a. JNDI-based lookup to access databases via logical names
b. Connection Pooling
c. Distributed transaction
d. The RowSet
28) The javax.sql package is used to develop the client/server sided applications and provide
server sided extension facilities. State the statement is true or false.
a. True
b. False
29) Using which classes and interfaces of javax.sql package we can establish and manage
connection with the data source?
a. Only DataSource
b. DataSource and DataManager
c. javax.sql
d. java.io.sql
a. DataSource
b. DataManager
c. DriverManager.
d. None
32) The ............................. Naming service is used to provide a logical name for the
DataSource to make a connection.
a. Java Database Connectivity (JDBC)
a True
b. false
b. PreparedStatement Interface
c. CallableStatement Interface
d. PreparedStatement Class
36) Which method is invoked on the statement object by p-assing the SQL statements as
parameter.
a. getXXX()
b. setXXX()
c. executeXXX()
d. All of the Above
37) ......................... can be used to represent a precompiled query , which can be executed
multiple times.
a. Statement Interface
b. PreparedStatement Interface
c. CallableStatement Interface
d. PreparedStatement Class
38) The excute method ....................... while using the PreparedStatement objects.
a. takes nth number of parameters.
b. takes only one parameters.
c. preparedStatement()
d. getStatement()
40) Which method is of the PreparedStatement object are used to set the parametrs of the
SQL statements.
a. getXXX()
b. setParameter()
c.setPath()
d. setXXX()
a) DataSource,XADataSource,ConnectionPoolDataSource
b) Data.XAData,ConnectionPoolData
c) Source.XASource,ConnectionPoolSource
d) source.xadatasource,connectionpoll
45) Connections made by using __________ objects are implemented on the middle-tier
connection pool.
a) DataSource
b) datasopurce
c) datasorce
d )none of the above
a) javax.sql.ConnectionPoolDataSource
b) java.sql.ConnectionPoolDataSource
c) javax.sqlConnectionPoolDataSource
d) javax.sql,ConnectionPoolDataSource
b) javax.sql.PooledConnectionInterface
c) javax.sqlConnectionPoolDataSource
d) javax.sql,ConnectionPoolDataSource
b) Non-Abstract
c) main
a) One
b) two
c) three
d) four
a) To create Database Object that provide and entry point for database connectivity
d) none
b) It is used to create Connection Object that provides an entry point for database
connectivity.
c) both a and b
a) ResultSet Object
b) Connection Object
c) PreparedStatement Object
a) ResultSet Object
b) Connection Object
c) PreparedStatement Object
54) How many times the query is compiled when used PreparedStatement?
a) once
b) twice
c) thrice
d) quadriple
b)resultset rs=stmt.executequery(“Query-to-be-executed");
c)ResultSet rs=stmt.executeQuery(“Query-to-be-executed");
d) None of the above
b)driver location
c)both a and b
a) i, ii, iii, iv
b) ii, iii,iv,i
c) iii, iv , ii , i
d)start->accessories->data sources
a)MicrosoftODBCForOracle
b) MicrosoftODBCforOracle
c) MicrosoftOdbcForOracle
d) MicrosoftOdbcforOracle
61) A Java program cannot directly communicate with an ODBC driver because .......
62) The JDBC-ODBC Bridge driver translates the JDBC API to the ODBC API and used
with ________
a) JDBC drivers
b) ODBC drivers
c) Both A and B
d) None of the above
63) The ............................. package contains classes that help in connecting to a database,
sending SQL statements to the database, and processing the query results.
a) connection.sql
b) db.sql
c) pkg.sql
d) java.sql
64) The ................................ method executes a simple query and returns a singleResult Set
object.
a) executeUpdate()
b) executeQuery()
c) execute()
d) noexecute()
65) The ......................... method executes an SQL statement that may return multiple results.
a) executeUpdate()
b) executeQuery()
c) execute()
d) noexecute()
67) The .................. object provides you with methods to access data from the table.
a) ResultSet
b) Parametrized
c) TableStatement
d) Condition
68) The parameters of the PreparedStatement object are ...................... when the user clicks
on the Query button.
a) initialized
b) started
c) paused
d) stopped
69) The ...................... method sets the query parameters of the PreparedStatement Object.
a) putString()
b) insertString()
c) setString()
d) setToString()
70) Connection object can be initialized using the ............................ method of the Driver
Manager class.
a) putConnection()
b) setConnection()
c) Connection()
d) getConnetion()
71) Which of the following statements is false as different type of statements is concern in
JDBC?
a)Regular Statement
b)Prepared Statement
c)Callable Statement
d)Interim Statement
72) JDBC-ODBC bridge supports multiple concurrent open statements per connection?
a)True
b)False
73) Which driver is efficient and always preferable for using JDBC application:
a)Type – 4
b)Type – 1
c)Type – 3
d)Type – 2
74) A Java program cannot directly communicate with an ODBC driver because
a) Statement is wrong
b) ODBC written in C language
c) ODBC written in high level language
d) None of above
77) API which controls access to the row result of a given Statement and holds data retrieved
from a database after you execute an SQL query using Statement objects.
a)java.Sql
b)java.ResultSet
c)Java.sql
d)java.sql.ResultSet
a)execute()
b)executeQuery()
c)executeUpdate()
d)executeResult()
81) How many transaction isolation levels are defined in sql.connection interface?
a)4
b)3
c)5
d)2
a)byte
b)int
c)boolean
d)char
a)execute()
b)executeQuery()
c)executeUpdate()
d)None of above
86) The ................................ method executes a simple query and returns a single Result Set
object.
a)executeUpdate()
b)executeQuery()
c) execute()
d) noexecute()
a)ResultSet
b)Parametrized
c)PreparedStatement
d)Condition
88) Three methods are central to the life cycle of a servlet ___________, __________ and
________ .
a)Driver name
b)database name
c)table name
d)data source name
90) What is output of following program.
import java.sql.*;
public class jdbc1
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:data");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from student");
while(rs.next())
{
System.out.println("id:"+rs.getInt("id"));
System.out.println("name:"+rs.getString("name1"));
}
con.close();
}
catch(SQLException e)
{}
catch(Exception e)
{
}
}}
a) "id:"+rs.getInt("id"
b)name:"+rs.getString("name1
c) both a and b
d)values of id and name will be displayed from table.
91) Which is the correct method ********for updating table rows from given option.
import java.sql.*;
public class Updatedbase
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:data");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from emp");
a)executeUpdate()
b)executeQuery()
c)execute()
d)ExecuteUpdate()
while(rs.next())
{
System.out.println("id:"+rs.getInt("id"))
System.out.println("name1:"+rs.getString("name1"));
}
con.close();
}
catch(SQLException e)
{}
catch(Exception e)
{
}
}}
import java.sql.*;
public class Selectdbase
{
public static void main(string args[])
{
try
{
Class.forname("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:data");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from emp");
while(rs.next())
{
System.out.println("id:"+rs.getInt("id"));
System.out.println("salary:"+rs.getString("salary"));
System.out.println("name:"+rs.getString("name1"));
}
con.close();
}
catch(SQLException e)
{}
catch(Exception e)
{
}
}}
a)Error in main()
b)Error in try block
c)both a and b
d)Error in catch block
import java.sql.*;
class MysqlCon
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection (
"jdbc:mysql://localhost:3306/sonoo","root","root");
Statement stmt=con.createStatement();
while(rs.next())
catch(Exception e)
System.out.println(e);
a.missing semicolon
c.missing brackets
d. both a and c
import java.sql.*;
class MysqlCon{
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sonoo","root","root");
//here sonoo is database name, root is username and password
Statement stmt=con.createStatement();
ResultSet rs=executeQuery("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close(); }
catch(Exception e){
System.out.println(e);}
}}
a)missing semicolon
b)incorrect syntax of Statement
c)incorrect syntax of ResultSet
d)both a and c
e)all of the above
import java.sql.*;
class MysqlCon{
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sonoo","root","root");
Statement stmt=createStatement();
while(rs.next())
con.close(); }
catch(Exception e){
System.out.println(e)}
}}
a.missing semicolon
d. both a and c
import java.awt.*;
class JdbcDemo {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
String url="jdbc:odbc:StudInfo";
Connection con=DriverManager.getConnection(url);
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
}}
catch(ClassNotFoundException e)
e.printStackTrace();
catch(SQLException e)
e.printStackTrace();
}}}
a)missing semicolon
b)missing bracket
98) What will be the output of the code considering the database is created:
import java.sql.*;
class JdbcDemo {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
String url="jdbc:odbc:StudInfo";
Connection con=DriverManager.getConnection(url);
System.out.println(" Connection to DataBase created");
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
}}
catch(ClassNotFoundException e)
e.printStackTrace();
catch(SQLException e)
e.printStackTrace();
}}}
a.
import java.awt.*;
class JdbcDemo {
try {
Class.forName("sun.jdbc.odbc");
System.out.println("Driver Loaded");
String url="jdbc:odbc:StudInfo";
Connection con=DriverManager.getConnection(url);
while(rs.next()){
}}
catch(ClassNotFoundException e)
e.printStackTrace();
catch(SQLException e)
e.printStackTrace();
a.missing semicolon
b.missing bracket
103) Class.forName("_________________________")
a) sun.jdbc.JdbcOdbcDriver
b) jdbc.odbc.JdbcOdbcDriver
c) sun.jdbc.odbc.JdbcOdbcDriver
d) sun.jdbc.odbc.JdbcOdbc
105) Connection object can be initialized using the _______ method of the DriverManager
Class.
a) getConnection()
b) getManager()
c) getconnection()
d) Getmanager()
106) createStatement() method without any parameter is used to create a statement with
forward only and read only ResultSet Database meta data are retrieved through
________.
a) PreparedStatement object
b) Statement object
c) Connection object
d) CollableStatement object
a) executeUpdate()
b) executeQuery()
c) Execute()
d) executeStatement()
109) Every driver must provide a class that should implement the __________________
a) Driver interface
b) Connection Interface
c) Statement Interface
d) Database Interface
a) String
b) Array
c) byte
d) Int
111) execution of delete SQL query in JDBC, ............. method must be used.
a) execute()
b) executeQuery()
c) executeUpdate()
d) executeStatement()
112) For execution of INSERT SQL query in JDBC, ............. method must be used.
a) executeUpdate()
b) executeStatement()
c) executeQuery()
d) Execute()
113) For execution of SELECT SQL query in JDBC, ___________________ method must
be used.
a) executeQuery()
b) Execute()
c) executeUpdate()
d) executeAll()
a) Static
b) Dynamic
a) DriverManager
b) Statement
c) Connection
d) None of above
116) How many JDBC driver types are available by sun Microsystem?
a) 6
b) 4
c) 5
d) 3
117) If a PreparedStatement is a SQL SELECT statement, you execute the statement using
________.
a) PreparedStatement.execute();
b) Statement.executeQuery();
c) PreparedStatement.executeQuery();
d) PreparedStatement.executeUpdate();
118) If you need to use a stored procedure with output parameters, which of the following
a) CallableStatement
b) PreparedStatement
c) Statement
d) ProcedureStatement
a) GUI
b) Server
c) Client
d) database
120) In the following JDBC drivers which is known as partly java driver?
a) Pure-Java Driver
c) JDBC driver
d) Native-API driver
121) In the three tier model the middle tier of the services acts as a mediator between
122) JDBC is a --------------------- interface, which means that it is used to invoke SQL
commands directly.
a) high level
b) low level
c) middle level
d) top level
d) None
a) IOException
b) Exception
c) DatabaseException
d) SQLException
126) Name the type number of driver belongs to JDBC ODBC Bridge driver?
a) Type 1
b) Type 2
c) Type 3
d) Type 4
128) Native – protocol pure Java converts ……….. in to the ………… used by DBMSs
directly.
a) Dependent
b) Independent
c) Both a and b
d) None
130) ODBC requires configuring _______ which represents the target database.
c) Domain Name
d) Database name
a) ?
b) *
c) &
d) #
a) Statement
b) Package
c) Class
d) Interface
a) Second Row
b) First Row
c) Last Row
d) Middle Row
a) DriverManager
b) Connection
c) Statement
d) ResultSet
a) Type-2 Driver
b) Type-3 Driver
c) Type-1 Driver
d) Type-4 Driver
143) Which interface provides methods to execute queries with the database?
a) Statement interface
b) Connection
c) Resultset
d) DriverManager
a) PreparedStatement
b) Statement
c) CallableStatement
d) Procedurestatement
a) TYPE_SCROLL_SENSITIVE
b) TYPE_SCROLL_INSENSITIVE
c) TYPE_FORWARD_ONLY
d) TYPE_SCROLL_FIRST
146) Which JDBC driver Type (s) can be used in either applet or servelt code?
a) Type 2
b) Type 3
c) Type 4
147) Which JDBC driver Type(s) can you use in a three-tier architecture and if the Web
server and the DBMS are running on the same machine?
a) Type 3
b) Type 2
c) Type 4
148) Which JDBC driver Types are used for over communications networks?
a) Type 2
b) Type 3
c) Type 4
a) getRow()
b) getrow()
c) GetRow()
d) Row()
a) executeQuery()
b) execute()
c) executeUpdate()
d) executeAll()
151) Which method of class is used to register & dynamically load the driver class?
a) forName()
b) DeviceManager
c) Statement
d) Resultset
152) which of the following function is used to find the column count of the particular
ResultSet ?
a) getColumnCount()
b) getRow
c) getcolumnCount()
d) getcolumncount()
a) Callable statements
b) Prepared Statement
c) Procedure Statement
d) Statement
154) Which type of driver converts JDBC calls into the network protocol used by the
database management system directely
a) Type 4
b) Type 3
c) Type 2
d) Type 1
b) JDBC-Native API
156) _______ calls get converted into native C or C++ API calls.
b) JDBC-Native API
a) ResultSet
b) Connection
c) Statement
d) DriverManager
158) All raw data types including binary documents or images should be read and uploaded
to the database as an array of ….
a) Byte
b) Int
c) String
d) Array
159) Analyse the following code and fill the appropriate statement in the blanks
import java.sql.*;
class DB
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydsn");
Statement stmt=con.createStatement();
where(rs.next())
System.out.println(rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getInt(4));
con.close();
Ans: executeQuery()
Class DemoFetch
Connection con;
Statement stmt;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url="Jdbc:Odbc:studdsn";
con=DriverManager.getConnection(url,"","");
stmt=con.createStatement();
System.out.println("Roll No\tName\tPercentage");
while(rs.next())
int rno=rs.getInt("roll");
String nm=rs.getString("sname");
double per=rs.getDouble("per");
System.out.println(rno+"\t"+nm+"\t"+per);
con.close();
catch(Exception e){}
}
Answer: stmt.executeQuery(qry)
import java.sql.*;
Class DemoFetch1
Connection con;
PreparedStatement pstmt;
ResultSet rs;
String qry,url;
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url="Jdbc:Odbc:studdsn";
con=DriverManager.getConnection(url,"","");
pstmt=con.prepareStatement(qry);
rs=___________________;
System.out.println("Roll No\tName\tPercentage");
while(rs.next())
int rno=rs.getInt("roll");
String nm=rs.getString("sname");
double per=rs.getDouble("per");
System.out.println(rno+"\t"+nm+"\t"+per);
con.close();
catch(Exception e)
System.out.println(e.toString());
Answer: pstmt.executeQuery(qry)
162)
while (rs.next())
Integer x = rs.getInt("c");
String s = rs.getString("a");
Float f = rs.getFloat("b");
a) getConnection()
b) Getconnection()
c) getStatement()
d) Getstatement()
import java.sql.*;
class exp2
try
Class.forName("_________________________________________");
Connection con=DriverManager.getConnection("Jdbc:Odbc:demo1dsn");
Statement st=con.createStatement();
while(rs.next())
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
}
st.executeUpdate("insert into Table1 values('jasmine',10,'banglore')");
while(rs1.next())
System.out.println(rs1.getString(1));
System.out.println(rs1.getString(2));
System.out.println(rs1.getString(3));
catch(Exception e) {}
Answer: sun.jdbc.odbc.JdbcOdbcDriver
165) Consider the following program. What should be the correction done in the program to
get correct output?
import java.sql.*;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement s = conn.createStatement();
String s1="update Table1 set name1='akash' where rollno='1'";
s.executeQuery(s1); s.close();
conn.close();
Answer: s.executeUpdate(s1)
166) Consider the following program. What should be the method used in following program
to get correct output?
import java.sql.*;
class Ddemo1
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement s=c.createStatement();
while(rs.next())
s.close();
c.close();
}
}
Answer: Connection()
167) Consider the following program. Select the statement that should be added to get correct
output.
import java.sql.*;
class DBEx
Try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:mydsn","","");
while(rs.next())
System.out.println("Name : "+rs.getString(2));
System.out.println("Branch :"+rs.getString("Branch")+"\n");
s.close();
c.close();
}
catch(Exception e)
System.out.println("Caught: "+e);
168) Consider the following program. Which two exceptions are thrown?
Package javaapplication21;
import java.sql.*;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:MyDSN","","");
System.out.println("Connection Established");
b) IOException
c) SQLException
d) Both a and c
a) java.security.permission
b) java.security
c) java.permission
d) None of above
a) 3
b) 4
c) 2
d) 1
172) Set XXX() method binds values to the parameters. Where XXX represents
a) Data Type
b) Method
c) Interface
d) Class
a)Three tiered
b)Multithreaded
c)Best for any platform
d)All of the above