Monday, June 26, 2017

JDBC mcqs

1. Which type of driver converts JDBC calls into the network protocol used by the database management system directly?
Ans: Type 4 driver

2. What happens if you call deleteRow() on a ResultSet object?
Ans: The row you are positioned on is deleted from the ResultSet and from the database

3.
PreparedStatement pstmt=null;
try{
//con is Connection Object 
String query="select * from persons where p_id";
pstmt=con.prepareStatement(query);
pstmt.setInt(1,12);
ResultSet rs=pstmt.executeQuery(Query);
while(rs.next())
{
System.out.println(rs.getString("p_name"));
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finaly
{
if(pstmt!=null)
{
pstmt.close();
}
}
Assuming the table persons contains two columns p_id and P_name and there is a row with p_id=12
What is the output of the above program?
Ans: The method will throw an SQL Exception because the queryString has been given again in the executeQuery method of the PreparedStatement

4. What is the return type of ResultSet.next()?
Ans: boolean

5. Which JDBC driver Type(s) can you see in a three-tier architecture and if the Web server and the DBMS are running on the same machine?
Ans: Both Type 3 and Type 4

6. What happens if you call the method close() on a ResultSet object?
Ans: The result set will be closed, the resources would be released and no more data can be retrieved from the result set

7. Which among the following is not a JDBC statement?
Ans: Called Statement

8. How do you use a savepoint?
Ans: A savepoint is used to mark intermediate points inside a transaction, in order to get a more fine-grained control. Transactions can be rolled back to a previous savepoint without affecting preceding work

9. Which statements about JDBC are true?
Ans: JDBC is an API to access relational databases, spreadsheets and flat files

10. try
{
Class.forName("oracle.jdbc.OracleDriver"); 
con=DriverManager.getConnection("jdbc:oracle:thin:@172.23.192.71:1521:javadb","USERID","PASSWORD");
ps=con.prepareStatement("insert into table1 values(?,?,?,?,?,?,?)");
ps.setString(1,cust.getCustName());
ps.setString(2,cust.getPassword());
ps.setLong(3,cust.getPhone());
ps.setString(1,cust.getEmail());
ps.execute();
}
catch
{
//catch block
}
What is the value of ps.execute?
Ans: False

11. What is the meaning of ResultSet.TYPE_SCROLL_INSENSITIVE?
Ans: This means that the ResultSet is sensitive to scrolling, but insensitive to changes made by others

12. How can you execute DML statements(i.e. insert, delete, update) in the database?
Ans: By invoking the execute(...) or executeUpdate(...) method of a normal statement object or a sub-interface object thereof

13. commit() method belongs to which interface?
Ans: Connection

14. Which JDBC driver Type(s) can be used in either applet or servlet code?
Ans: Both Type 3 and Type 4

15. What statements are correct about batched insert and updates?
Ans: To do a batched update/insert, you call addBatch(String statement) on a statement object for each statement you want to execute in the batch

16. Consider the following code statement Class.forName(driverName); where driverName is the name of the driver for the corresponding DB, if the jdbc jar is not specified in class path, then which of the exceptions is obtained?
Ans: ClassNotFoundException

17. How can you retrieve information from a ResultSet?
Ans: By involving the special getter methods on the ResultSet: getString(...), getBoolean(...), getClob(...)....

18. What is the correct Sequence in which most relational databases handles a JDBC/ SQL query.
      1. Parse the incoming SQL query
      2. Compile the SQL query
      3. Plan/optimize the data acquisition path
      4. Execute the optimized query/acquire and return data
Ans: 1,2,3,4

19. What is the return type of executeUpdate()?
Ans: int

20. Which packages contain the JDBC classes?
Ans: java.sql and javax.sql

21. Which object allows you to execute parameterized queries?
Ans: PreparedStatement

22. What is used to execute parameterized query?
Ans:  PreparedStatement interface

23. How many JDBC driver types are there?
Ans: Four

24. JDBC stands for
Ans: Java Database Connectivity

25. Which of the following is a best practice?
Ans: At the end of the JDBC program, close the ResultSet, Statement and Connection objects one after the other

26. What is the meaning of TRANSACTION_REPEATABLE_READ?
Ans: Dirty reads are prevented: non-repeatable reads and phanthom reads can occur

27. The JDBC API has always supported persistent storage through the methods getObject() and setObject()
Ans: True

28. Return type of ResultSet.next() is
Ans: Boolean

29. What is correct about DDL statements
Ans: DDL statements are treated as normal SQL statements

4 comments:

  1. 1. Which type of driver converts JDBC calls into the network protocol used by the database management system directly?
    Ans: Type 3 driver
    wrong answer

    ReplyDelete
  2. Thank you for your comment. The correct answer is updated. (Type 4 Driver)

    ReplyDelete
  3. A common motive in the back of failure is that applicants don’t know wherein and up to dateupdated get valid Splunk SPLK -1002 questions pdf dumps up to date get success guaranteed. They waste their Splunk SPLK-1002 Exam Dumps cash as well asupdated treasured time on irrelevant questions for Splunk core licensed energy consumer exam however DumpsBoss gives you 100% legitimate and coming SPLK -1002 questions pdf dumps up-to-date get success inside the first actual strive.

    ReplyDelete
  4. Thanks for your marvelous posting! I genuinely enjoyed reading MD-102

    ReplyDelete