0% found this document useful (0 votes)
17 views

Chapter_5.gpp

Uploaded by

Sai Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Chapter_5.gpp

Uploaded by

Sai Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Chapter 5

Interacting with Database

Each question carries 1 Marks

Q1. Which type of Statement can execute parameterized queries?

A) ParameterizedStatement B) PreparedStatement
C) ParameterizedStatement and CallableStatement
D) All kinds of Statements

Q2. How can you retrieve information from a ResultSet?

A) By invoking the method get(String type) on the ResultSet, where type is the
database type

B) By invoking the method get(Type type) on the ResultSet, where Type is an object
which represents a databasetype

C) By invoking the method getValue(), and cast the result to the desired Java type

D) By invoking the special getter methods on the ResultSet: getString(),


getBoolean(), getClob()

Q3. Which type of statement can execute parameterized queries ?

A) PreparedStatement B)
ParameterizedStatement C) CallableStatement D)
All of the Above

Q4. What is the meaning of ResultSet.TYPE_SCROLL_INSENSITIVE

A) This means that the ResultSet is insensitive to scrolling

B) This means that the Resultset is sensitive toscrolling, but insensitive to updates, i.e.
not updateable

C) This means that the ResultSet is sensitive to scrolling, but insensitive to


changes made by others

D) The meaning depends on the type of data source, and the type and version of the
driver you use with this data source

Q5. What statements are correct about JDBC transactions

A) A transaction is a set of successfully executed statements in the database


B) A transaction is finished when commit() or rollback() is called on the Connection
object

C) A transaction is finished when commit()or rollback() is called on the Transaction


object

D) A transaction is finished when close() is called on the Connection object

Q6. What happens if you call the method close() on a ResultSet object?

A) the method close() does not exist for a ResultSet. Only Connections can be
closed.

B) the database and JDBC resources are released

C) you will get a SQLException, because only Statement objects can close
ResultSets

D) the ResultSet, together with the Statement which created it and the Connection
fromwhich the Statement was retrieved, will be closed and release all database and
JDBC resources
Q7. What happens if you call deleteRow() on a ResultSet object?

A) The row you are positioned on is deleted from the ResultSet, but not from the
database.

B) The row youare positioned on is deleted from the ResultSet and from the
database

C) The result depends on whether the property synchronizeWithDataSource is set to


true or false.

D) You will get a compile error: the methoddoes not exist because you can not delete
rows from a ResultSet.

Q8. What is correct about DDL statements

A) DDL statements are treated as normal SQL statements, and are executed by
calling the execute() method on a Statement

B) To execute DDL statements, you have to install additional support files

C) DDLstatements can not be executed by making use of JDBC, you should use the
native database tools for this
D) Support for DDL statements will be a feature of a future release of JDBC

Q9. Which of the following statements is false as far as different type of statements is
concern inJDBC?
A) Regular Statement B) Prepared
Statement C) Callable Statement D) Interim
Statement

Q10. JDBC facilitates to store the java objects by using which of the methods of Prepared
Statement 1.setObject () 2. setBlob() 3. setClob()

A) 1, 2 B) 1, 2,3 C) 1,3 D) 2,3

Q11. method to establish actual database connection

A) executeQuery() B) executeUpdate() C) getConnection() D) prepareCall()

Q12. Which of the following describes the correct sequence of the steps involved in making a
connection with a database. 1. Loading the driver 2. Process the results. 3. Making the
connection with thedatabase. 4. Executing the SQL statements.

A) 1,3,4,2 B) 1,2,3,4 C) 2,1,3,4 D) 4,1,2,3

Q13. Which method is used to perform DML statements in JDBC?

A) execute() B) executeQuery() C) executeUpdate() D) executeResult()

Q14. Can we retrieve a whole row of data at once, instead of calling an individual
ResultSet.getXXXmethod for each column ?

A) No B) Yes C) Statement is incorrect


D) None of the above

Q15. Are Prepared Statements actually compiled?

A) Yes B) No C) Statement is incorrect D) None of the


above

Q16. In order to transfer data between a database and an application written in the Java
programminglanguage, the JDBC API provides which of these methods?

A) Methods on the ResultSet class for retrieving SQL SELECT results as Java types.

B) Methods on thePreparedStatement class for sending Java types as SQL statement


parameters.

C) Methods on the CallableStatement class for retrieving SQL OUT parameters as


Java types.

D) All mentioned above

Q17. calls get converted into native c or c++ API calls.

A) API B) ODBC C) JDBC API D) None of the


above.
Q18. Which method Drops all changes made since the previous commit/rollback?

A) public void rollback() B) public void


commit() C) public void close() D) public Statement
createStatement()

Q19. Which of the following is used to set the maximum number of rows can contain?

A) setMaxRows(int i) B) setMinRows(int i) C) getMaxrows(int i) D)


getMinRows(int i)

Q20. method of ResultSet is used to move the cursor to the row next from the current
position.

A) fetch method B) current method C) next method D) access


method

Q21. Which of the following encapsulates an SQL statement which is passed to the database
to beparsed, compiled, planned and executed?

A) DriverManager B) JDBC driver C) Connection D)


Statement

Q22. The interface ResultSet has a method, getMetaData(), that returns a/an

A) Tuple B) Value C) Object D) Result

Q23. Which method is used to find the number of column in ResultSet?

A) getNumberOfColumn() B) getMaxColumn()
C) getColumnCount() D) getColumns()

Q24. commit() method is belongs to which interface?

A) ResultSet B) Statement
C) PreparedStatement D) Connection

Q25. Which one is the correct syntax for creating a Statement?

A) Statement stmt = connection.createStatements();


B) Statement stmt = connection.preparedStatement();
C) Statement stmt = connection.createStatement();

D) none of these

Q26. Which statement is correct?

A) ResultSet rs = stmt.selectQuery("SELECT ROLLNO,STUDNAME FROM


STUDENT");
B) ResultSet rs= stmt.executeSelect("SELECT ROLLNO,STUDNAME FROM
STUDENT");
C) ResultSet rs = stmt.executeUpdate("SELECT ROLLNO,STUDNAME FROM
STUDENT");
D) ResultSet rs = stmt.executeQuery("SELECT ROLLNO,STUDNAME FROM
STUDENT");
Q27. INSERT, DELETE, UPDATE comes under ?
A) Data Modification Language B) Data Definition Language
C) Data Control Language D) DataManipulation
Language
Q28. The return type of execute(String query) is?
A) int B) ResultSet C) boolean D) void
Q29. which method is used to insert image in database
A) statement.getImage() B) statement.getDouble()
C) statement.getBLOB() D) statement.getIcon()
Q30. All raw data types (including binary documents or images) should be read and
uploaded to thedatabase as an array of
A) byte B) int C) char D) long
Q31. In JDBC imports all java classes concerned with database connectivity.
A) javax.sql.* B) java.mysql.* C) java.sql.* D) com.*
Q32. Methods of ResultSet throws exception.
A) IOException B)
SQLException C) MethodNotFoundException D)
ResultSetException
Q33. Which of the following is FALSE with reference to JDBC Driver
A) All drivers implements the java.sql.Driver interface.
B) driver classes are not supplied by the database vendor
C) Driver class return a java.sql.Connection object.
D) None of the Above
Q34. Match the following i) Type 1 Driver a) Native API, partly Java ii)Type 2 Driver b)
Pure Java directto database iii)Type 3 Driver c) JDBC-ODBC bridge iv)Type 4 Driver d)
Pure Java to database middleware
A) i -> c, ii -> b , iii -> d, iv -> a B) i -> c, ii -> a , iii -> d, iv -> b
C) i -> c, ii -> a , iii -> b, iv -> d D) i -> c, ii-> d , iii -> a, iv -> b
Q35. Which type of Driver communicate using a network protocol to a middleware server
A) Type 1 Driver B) Type 2 Driver C) Type 3 Driver D) Type 4
Driver
Q36. Which of the Following Drivers Sun describes it as being experimental and
appropriate for useonly where no other driver is available.
A) Type 1 Driver B) Type 2 Driver C) Type 3 Driver D) Type 4 Driver
Q37. ______________________interface allows storing results of query?
A) ResultSet B) Connection C) Statement D) Result
Q38. Which of the Following Drivers require native library files to be installed &
configured on clientsystems.
A) Type 1 Driver B) Type 2 Driver C) Type 3 Driver D) Type 4
Driver
Q39. Which of the following statements are TRUE in case of Type 2 JDBC Drivers
A) It use native methods to call vendor-specific API functions.
B) native library files are to be installed on client systems.
C) Both of the Above
D) None of the Above
Q40. in JDBC 2.0 a Connection object is created either by a call to
A) DriverManager.getConnection() B)
DataSource.Connection()
C) Both of the Above D) None of theAbove
Q41. In JDBC URL string protocol is always
A) jdbc B) odbc C) Jdbc-odbc D) Any one of the above
Q42. Which of the following is FALSE with reference to JDBC database URL
A) URL string has three components B) protocol in URL string is always
jdbc
C) subprotocol in URL stringis always odbc.
D) subname identifies the specific database to connect
Q43. Which class has strong support of the JDBC architecture?
A) The JDBC driver manager B) JDBC driver test suite
C) JDBC ODBC bridge D) All of these
Q44. Connection object can be initialized using the _______ method of the Driver
ManagerClass.
A) putConnection() B) setConnection() C) Connection() D)
getConnection()
Q45. Which of the following methods are needed for loading a database driver in JDBC?
A) registerDriver() method B) Class.forName () C) Both A and B
D) getConnection ()
Q46. Native API converts _______ into the ___________ used by DBMS.
A) JDBC API, network protocol B) JDBC API, Native API
calls
C) JDBC API, User call D) JDBC API,ODBC API
calls
Q47. ______ method of DriverManager class is used to establish connection with the
database.
A) openConnection() B) getConnection()
C) connect() D) createConnection()
Q48. subname part of JDBC URL string NOT contains
A) Database name B) Username & password
C) Port number D) Protocol
Q49. Which of the following type of JDBC driver, is also called Type 3 JDBC driver?
A) JDBC-ODBC Bridge plus ODBC driver B) Native-API, partly Java driver
C) JDBC-Net, pure Javadriver D) Native-protocol, pure Java
driver
Q50. Which of the following type of JDBC driver, is also called Type 1 JDBC driver
A) JDBC-ODBC Bridge Driver B) Native API/ Partly java driver
C) All java / Net-protocol driver D)Native protocol / all-java driver
Q51. Which of the following type of JDBC driver, is also called Type 2 JDBC driver
A) Native API/ Partly java driver B) JDBC-ODBC Bridge Driver
C) Native protocol / all-java driver D) Alljava / Net-protocol driver
Q52. Which of the following type of JDBC driver, is also called Type 4 JDBC driver
A) All java / Net-protocol driver B) Native protocol / all-java driver
C) Native API/ Partly java driver D)JDBC-ODBC Bridge Driver
Q53. Which one of the following is the correct sequence of activities to perform for
databaseconnectivity in java
A) Register the Driver class - Create statement - Create connection - Execute queries -
Close connection
B) Register the Driver class - Create connection - Create statement -Execute queries -
Close connection
C) Create connection - Register the Driver class - Create statement -Execute queries -
Close connection
D) Create connection - Create statement - Register the Driver class - Execute queries -
Close connection
Q54. Application program interface in two tier architecture database management system is
providedby the
A) close module connectivity B) open module connectivity
C) close database connectivity D) opendatabase connectivity
Q55. Database system compiles query when it is
A) prepared B) invoked C) executed D) initialized
Q56. Standard which allows access to DBMS by Java client programs is classified as
A) JCBD standard B) JDBC standard C) BDJC standard D) CJBD
standard
Q57. Which of the Following is NOT a valid Syntax for getConnection() Method
A) public static Connection getConnection(String url)

B) public static Connection getConnection(String url, String userID, String password)

C) public static Connection getConnection(jdbc:<subprotocol>: <subname>String userID,


String password)

D) None of the Above


Q58. In two-tier client/server architecture, running of application programs and user
interface programsis in control of __________
A) modulation side B) client side C) server side D) host side
Q59. Which of the following must be closed at end of Java program ?
A) Result B) Connection C) Query D) Both A and B
Q60. A Java application program does not include declarations for
A) Data stored in database B) Data retrieved of database
C) Data executed D) Data manipulated
Q61. Which of the following Statement is NOT true for Type-2 Drivers
A) Driver needs to be installed separately in individual client machines

B) The Vendor client library needsto be installed on client machine.

C) Type-2 driver isn't written in java, that's why it isn't a portable driver

D) None of the Above


Q62. With respect to Type-3 drivers A)Type-3 drivers are fully written in Java, hence they
are portabledrivers. B)No client side library is required because of application server that
can perform many tasks like auditing, load balancing, logging etc.
A) A is True But B is False B) B is True But A is False
C) Both are False D) Both are True
Q63. Which of the following is NOT true for Type - 4 drivers
A) Type-4 driver is also called native protocol driver.
B) Different driver is not needed for different database.
C) No client-side or server-side installation required.
D) It is fully written in Java language, hence they are portable drivers
Q64. Which of the following statement is used to establish connection with mysql database.
A) Connection conn =
DriverManager.getConnection(jdbc:mysql://localhost:3306/booksdb,user,passwor
d);
B) Connection conn =
DriverManager.getConnected(jdbc:mysql://localhost:3306/booksdb,user, password);
C) Connection conn =
DriverManager.getConnection(jdbc:odbc:mysql://localhost:3306/booksdb,user,password)
;
D) Connection conn =
DriverManager.getConnection(localhost:3306/booksdb,user,password);
Q65. PreparedStatement interface extends which interface?
A) Statement B) CallableStatement C) ResultSet D) None of the
above
Q66. Find out the correct statement
A) public PreparedStatement prepareStatement(String query)throws IOException{}
B) private PreparedStatement preparedStatement(String query)throws IOException{}
C) public PreparedStatementprepareStatement(String query)throws SQLException{}
D) protected PrepareStatement prepareStatement(String query)throws
FileNotFoundException{}
Q67. Which are the parameters of setString() method?
A) String value,String paramIndex B) String paramIndex, String
value C) int paramIndex, int value D) intparamIndex, String value
Q68. What is the return type of executeQuery() method?
A) int B) connection C) ResultSet D) None of the above
Q69. Choose the correct syntax to create a table student with attributes rollno,studname,
marks
A) CREATE TABLE STUDENT VALUES (ROLLNO 1, STUDNAME "ABC",MARKS
90);
B) CREATE TABLE STUDENT (ROLLNO INT, STUDNAME VARCHAR(10),
MARKS INT);
C) CREATE TABLE STUDENT (ROLLNO NUMBER, STUDNAME STRING, MARKS
INT);
D) All of the Above
Q70. What parameter we can pass to public int getInt() method?

A) int columnIndex B) int row C) Both D) None of the above


Q71. What is in terms of JDBC ,a DataSource
A) A DataSource is the basic service for managing a set of JDBC drivers
B) DataSource is a java representation of physical data source
C) DataSource is a registry point
D) DataSource is a factory of connections to a physical data source
Q72. Which of the following encapsulates an SQL statement which is passed to the database
to beparsed, compiled, planned and executed?
A) DriverManager B) Connection C) JDBC Driver D) Statement
Q73. Which of the following methods are needed for loading the database driver in JDBC?
A) resultSet method B) class.forName()
method C) getConnection() D) Both A and B
Q74. Is the JDBC-ODBC bridge multithreaded ?
A) True B) False C) can't predict D) don't know
Q75. ____________ is an open source DBMS product that runs on UNIX, Linux and
Windows
A) MySQL B) JSP/SQL C) JDBC/SQL D) Sun ACCESS
Q76. Which model does a Java applet or application talks directly to the data source?
A) Two Tier Model B) Three Tier Mode
l C) Both A and B D) None of the above
Q77. What is the reason that a java program cannot directly communicate with an ODBC
driver?
A) ODBC written in C# language
B) ODBC written in C language
C) ODBC written in C++ language
D)None of the above
Q78. Which models do the JDBC API support for the database access?
A) Two Tier Model B) Three Tier Model
C) Both A and B D) None of the above
Q79. ODBC stands for?
A) Open database connectivity B) Open database concept
C) Open database communications D) Noneof the above
Q80. Which of the following is correct about driver interface of JDBC?
A) JDBC driver is an interface enabling a Java application to interact with a database.
B) JDBC API is anapplication interface of javafor connecting java as back end
C) Both A and B
D) None of the above
Q81. Which of the following is correct about Statement?
A) Used for general-purpose access to your database.
B) Useful when you are using static SQL statements at runtime.
C) Both of the above.
D) None of the above.
Q82. The __________ method executes an SQL statement that may return multiple results.
A) .executeUpdate() B) executeQuery() C) execute() D)
noexecute()
Q83. Every driver must provide a class that should implement the ____________
A) Driver interface B) Driver manager C) Driver class D) Driver
Q84. How can you execute a stored procedure in the database?
A) Call method execute() on a CallableStatement object
B) Call method executeProcedure() on a Statement object
C) Call method execute() on a StoredProcedure object
D) Call method run() on aProcedureCommand object
Q85. Which of the following is false as far as type 4 driver is concern?
A) Type 4 driver is native protocol, pure java driver

B) Type 4 drivers are 100% Java compatible

C) Type4 drivers uses Socket class to connect to the database

D) Type 4 drivers can not be used with Netscape

Q86. The JDBC-ODBC bridge is


A) Three tiered B) Multithreaded C) Best for any platform D) All of the
above
Q87. Which of the following are the different methods of ResultSet interface? 1. public
boolean next() 2. public boolean previous() 3. public boolean back() 4. public boolean last()
A) 1,2,3 B) 1,2,4 C) 2,3,4 D) All of the above.
Q88. Which of the following are the different methods of Statement interface? 1. public
int[] executeBatch() 2. public boolean execute(String sql) 3. public int executeUpdate(String
sql) 4. public intinsert(String sql)
A) 1,2,3 B) 2,3,4 C) 1,3,4 D) All of the above.
Q89. Consider the following program, Select the statement that should be added to the
program to get correct output.

import java.sql.*;

public class MyData


{

public static void main(String args[])throws Exception

{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:MyDSN","","");
PreparedStatement s=c.prepareStatement( "update student set Name=* where Roll_no=*");
s.setString(1,"XYZ");
s.setString(2,"1");
s.executeUpdate();
s.close();
c.close(); } }
A) a. use s.executeQuery() method B) Use ; in main method
C) Use s.setString(2,1) method D) use ? inPreparedStatement
Q90. Which is the incorrect statement in the following Code?
import java.sql.*;
public class Sample1
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:DSN2","","");
PreparedStatement s=c.createStatement( );
ResultSet rs=s.executeQuery("select* from student");
System.out.println("Name"+""+"Roll no"+" "+"Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" "+rs.getInt(2)+" "+rs.getDouble(3));
}
s.close();
c.close();
}
}
A) ResultSet rs=s.executeQuery(); B)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); C) PreparedStatement
s=c.createStatement(); D) None of the above
Q91. Consider the following program. What should be the correction done in the program to
get correctoutput?
import java.sql.*;
public class DataBase
{
public static void main(String[] args)
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:abc", "", "");
String s1="insert into student values(1,'abc');
s.executeUpdate(s1);
s.close();
conn.close();
}
catch(IOException e)
{
System.out.println(e);
}
}
}
A) Insert try and catch(FileNotFoundException fe)
B) Use s.executeQuery(s1);
C) Insert try and catch(Exception e)
D) Insert catch(Exception e)
Q92. What will be the output of the following program.

import java.sql.*;

import java.io.*;

public class RetrieveImage

public static void main(String[] args)

{
Try

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");

PreparedStatement ps=con.prepareStatement("select * from imgtable");

ResultSet rs=ps.executeQuery();

if(rs.next())

Blob b=rs.getBlob(2);

data byte barr[]=b.getBytes(1,(int)b.length());

FileOutputStream fout=newFileOutputStream("d:\picture.jpg");

fout.write(barr);

fout.close();

}//end of if

con.close();

catch (Exception e)

{
e.printStackTrace();
}
}
}
A) image will be inserted into the database
B) Image will be retrieved from the database.
C) ; missing
D) } missing
Q93. Which of the following statement is used for connectivity with Oracle database?
A) Connection
con=DriverManager.getConnection("odbc:oracle:thin:@localhost:1512:xe","system","or
acle");
B) Connection
con=DriverManager.getConnection("jdbc:thin:oracle:@localhost:1512:xe","system","or
acle"); C) Connection
con=DriverManager.getConnection("odbc:oracle:thin:@localhost:1521:xe","system","o
racle");
D) Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system",
"oracle");
Q94. Consider the following code. Fill the proper method in the blank space to get the
count of total records updated.

import java.sql.Statement;

public class MyExecuteMethod

public static void main(String a[] )

Try

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection con = DriverManager. getConnection


getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");

Statement stmt = con.createStatement(); //The query can be update query or can be select
query

String query = "select * fromemp";

boolean status = stmt.execute(query);

if(status)

ResultSet rs = stmt.getResultSet();

while(rs.next())

System.out.println(rs.getString(1));

rs.close();
}

Else

int count = stmt ------------------------------------------------------------------------------------ ;

System.out.println("Total records updated: "+count);


}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
A) getUpdateCount(); B) getCount(); C) readCount(); D)
readUpdateCount();
Q95. A programmer uses a Java class known as ________ to connect to a database
A) JDBC driver B) Package C) JDBC Interface D) none of the Above
Q96. _________ is a call-level interface.
A) Oracle's Oracle Call Interface (OCI) B) Microsoft's Open Database Connectivity
(ODBC) C) JDBC D)All of the Above
Q97. Because of _______ coupling a 2 tiered application will run__________
A) loose, faster B) tight, faster C) loose, slower D) tight, slower
Q98. Which of the Following is NOT true for Two Tier Architecture
A) The direct communication takes place between client and server.
B) There is no intermediate betweenclient and server.
C) A 2 tiered application will run faster.
D) In two tier architecture the server can respond multiple request same time
Q99. A driver is used to __________ to a particular database.
A) issue sql queries B) open a connection C) load database D) load resultset
Q100. By using which interface one can store images in the database in java
A) ResultSet interface B) PreparedStatement interface
C) Connection interface D) None of the above

You might also like