latest Post

Upwork JDBC 2.1 Test Answers

JBDC (Java Database Connectivity)
1. Under which category does the following driver fall:

 WebLogic's Tengah "all Java Type-3 driver"
 Answers: • Net-Protocol All-Java Driver

 2. Which JDBC driver is considered best in terms of performance and efficiency?
 Answers: • Type-1 Driver

 3. Please select all the correct options. JDBC Driver Manager is:
 Answers: • Able to activate registered drivers

 4. Consider the following statement:

 PreparedStatement ps=con.prepareStatement("INSERT INTO ORDER (CUSTOMER_ID ,PRICE) VALUES(?,?)");

 Which of the following should come after this statement?
 Answers: • ps.clearParameters(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate();

 5. You want to start a transaction for bank account processing. Which of the following methods will you execute on the Connection object to begin it?
 Answers: • con.setAutoCommit(false);

 6. You need to use a third party driver for establishing a connection with the database. The subprotocol is "webx" and the DSN is "webdsn". What is the syntax of the URL?
 Answers: • jdbc:webx:webdsn

 7. You have to handle an erroneous situation in a transaction. Which method comes handy in this case?
 Answers: • con.rollback();

 8. How will you create a new instance of a JDBC driver explicitly?
 Answers: • Class.forName("driver").newInstance();

 9. JDBC is based on:
 Answers: • X/Open CLI (Call Level Interface)

 10. You are developing a shopping cart for your client. Where would you like to put your business logic?
 Answers: • In middleware servlets

 11. You want to execute the following query string, using the connection named "con":

 String query = "SELECT * FROM CUSTOMER";

 What should the syntax be?
 Answers: • Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query);

 12. Which exception will be thrown in your code, if the specified driver could not be loaded?
 Answers: • ClassNotFoundException

 13. A process allows you to group multiple SQL statements. Commit or Rollback can be performed on the group together. This process is known as:
 Answers: • Transaction

 14. Which of the following JDBC methods is used for retrieving large text strings?
 Answers: • getAsciiStream

 15. Open Database Connectivity is:
 Answers: • Platform independent

 16. Which of the following methods eliminates the need to call wasNull() method to handle null database fields?
 Answers: • getObject();

 17. Transactions have a property called atomicity, which means:
 Answers: • Everything takes place once

 18. What should the syntax be to establish a connection with a Database?
 Answers: • Connection con = DriverManager.getConnection(url,"myLogin", "myPassword");

 19. ResultSet objects follow index patterns of:
 Answers: • Array standard

 20. When you are handling user-submitted SQL, you may retrieve a ResultSet or a count. Which of the following methods is handy in this situation?
 Answers: • execute()

 21. You want to execute a CallableStatement named 'cs'. It is expected to return multiples results. Which of the following methods will you choose?
 Answers: • ResultSet rs=cs.execute()

 22. Your project leader has asked you to improve the performance of JDBC connectivity by reusing objects in your Servlet's code. Which of the following is an appropriate solution?
 Answers: • Reuse the database connection and use PreparedStatement objects with synchronized blocks

 23. Which of the following methods will you use to execute INSERT, UPDATE and DELETE SQL statements?
 Answers: • executeUpdate();

 24. How do you register a JDBC driver?
 Answers: • Class.forName("driver");

 25. Which of the following JDBC methods is used for retrieving large binary objects?
 Answers: • getBinaryStream

 26. Name the interface you will use to retrieve the underlying structure of the query result:
 Answers: • ResultSetMetaData

 27. Which type of statement object will you use to execute a stored procedure?
 Answers: • CallableStatement

 28. A warning can be thrown by a Connection object, a Statement object or a ResultSet object. Which method is used to retrieve the warning:
 Answers: • getWarnings()

 29. You have obtained a ResultSet object named 'rs' after executing the following query:


 Which loop can you use to return all the records in the ResultSet?
 Answers: • while(

 30. You executed a query to retrieve 40 products from the database and obtained a scrollable ResultSet named 'scrollrs'. You started scrolling the ResultSet as follows:;

 At which row number is the cursor currently located?
 Answers: • 24

 31. The code segment below defines a query:


 Which of the following code snippets will create a scrollable ResultSet?
 Answers: • Statement st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet srs=st.executeQuery(qry);

 32. Which of the following is the syntax for creating a CallableStatement?
 Answers: • CallableStatement cs=con.prepareCall("{call SHOW_ORDER}")

 33. Which of the following is not true?
 Answers: • CallableStatement cannot take INOUT parameters

 34. Which of the following is not true for a ResultSet?
 Answers: • Methods next() and previous() return -1 beyond the ResultSet

 35. Java Database Connectivity (JDBC) is a:
 Answers: • Database-independent API

 36. Servlet developers should avoid using JDBC-ODBC bridge driver because:
 Answers: • The driver is of Type-1

 37. You have obtained a scrollable ResultSet named 'srs' by executing a query. Which of the following methods will you use to verify the position of the cursor?
 Answers: • srs.getRow()

 38. A user leaves an online shopping cart without checking out. Which of following interfaces will notify to Rollback the transaction?
 Answers: • HttpSessionBindingListener

 39. After executing the following code, resultvar contains false. What should the next step be?

 boolean resultvar=stmt.execute(sql);
 Answers: • stmt.getUpdateCount();

 40. SQLException has a method, which provides the feature of chaining or encapsulation of additional Exception objects. Identify the method from the following:
 Answers: • getNextException()

 41. Your project leader has given you a new task. You have to work on a module in which the transaction has to be extended across multiple page requests and multiple servlets. How will you implement this?
 Answers: • By session tracking and using HttpSession to hold a connection for each user

 42. SQLWarning object deals with database access warnings. It is a subclass of:
 Answers: • SQLException

 43. Will the below script execute properly?

 Answers: • Yes. The table will be created successfully.

 44. You are trying to connect to a database through JDBC. There is a problem with one of the methods immediately after the driver has been loaded. Which exception will be thrown?
 Answers: • SQLException

About Sandesh Saini

Sandesh Saini
Recommended Posts × +


Post a Comment