Friday, November 11, 2016

Upwork JDBC 2.1 Test Answers 2016

Upwork JDBC 2.1 Test 2016

44 Answered Test Questions:
1. Under which category does the following driver fall:
WebLogic’s Tengah “all Java Type-3 driver”
Answers:
a. JDBC-ODBC Bridge Driver
a. Native-API Partly-Java Driver
a. Net-Protocol All-Java Driver
a. Native-Protocol All-Java Driver
a. Native-Protocol Part-Java Driver
2. Which JDBC driver is considered best in terms of performance and efficiency?
Answers:
a. Type-1 Driver
a. Type-2 Driver
a. Type-3 Driver
a. Type-4 Driver
3. Please select all the correct options. JDBC Driver Manager is:
Answers:
a. Able to activate registered drivers
a. Able to activate unregistered drivers
a. Not required for activation of drivers with DataSource
a. Required for activation of drivers with DataSource
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:
a. ps.clearParameters(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate(sql);
a. ps.clearParameters(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate();
a. ps.clear(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate(sql);
a. ps.clearParameters(); ps.setInt(1,3.09); ps.setDouble(2,790.50); ps.execute(sql);
a. ps.clearParameters(); ps.setDouble(2,790.50); ps.execute(sql);
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:
a. con.setAutoCommit(false); 
a. con.setCommit(false);
a. con.setAutoCommit();
a. con.setAutoCommit(true);
a. con.autoCommit();
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:
a. jdbc:odbc:webx:webdsn
a. odbc:jdbc:webx:webdsn
a. jdbc:webx:webdsn
a. thin:jdbc:odbc:dsn:webdsn
a. thick:jdbc:odbc:dsn:webdsn
a. None of the above
7. You have to handle an erroneous situation in a transaction. Which method comes handy in this case?
Answers:
a. con.commit(false);
a. con.commit();
a. con.rollback();
a. con.revertback();
a. con.rollback(true);
8. How will you create a new instance of a JDBC driver explicitly?
Answers:
a. Class.forName(“driver”);
a. Class.newInstance(“driver”);
a. Class.driver(“driver”);
a. Class.getDriver(“driver”);
a. Class.forName(“driver”).newInstance();
9. JDBC is based on:
Answers:
a. X/Open CLI (Call Level Interface) 
a. JDBC/Open CLI
a. Java/Open CLI
a. V/OPEN CLI
a. X/Close CLI
10. You are developing a shopping cart for your client. Where would you like to put your business logic?
Answers:
a. Inside the database
a. Inside the client application
a. In middleware servlets
a. In COM / DCOM components
a. Inside the code for the cart
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:
a. Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query); 
a. Statement stmt=new Statement(); ResultSet rs=stmt.executeQuery(query);
a. Statement stmt=con.createStatement(); ResultSet rs=stmt.execute(query);
a. Statement stmt=con.getStatement(); ResultSet rs=stmt.executeQuery(query);
a. Statement stmt=con.getStatement(); ResultSet rs=con.executeQuery(query);
12. Which exception will be thrown in your code, if the specified driver could not be loaded?
Answers:
a. ActivationException
a. ClassNotFoundException
a. ClassNotAvailableException
a. ClassUnavailableException
a. InstantiationException
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:
a. Binding
a. Synchronization
a. Registry
a. Transaction
a. Late binding
14. Which of the following JDBC methods is used for retrieving large text strings?
Answers:
a. getBinaryStream
a. getText
a. getAsciiStream
a. getString
a. getObjectStream
15. Open Database Connectivity is:
Answers:
a. Platform independent
a. Platform dependent
a. Architecture neutral
a. Network independent
a. Machine independent
16. Which of the following methods eliminates the need to call wasNull() method to handle null database fields?
Answers:
a. getObject();
a. getInt();
a. getString();
a. getFloat();
a. getNull();
17. Transactions have a property called atomicity, which means:
Answers:
a. Everything takes place one by one
a. Everything takes place once
a. Everything takes place randomly
a. Everything takes place twice
a. Everything takes place thrice
18. What should the syntax be to establish a connection with a Database?
Answers:
a. Connection con = DriverManager.getConnection(url,”myLogin”, “myPassword”);
a. Connection con = DriverManager.getConnection(“myLogin”, “myPassword”,url);
a. Connection con = DriverManager.getConnection(“myLogin”, “myPassword”);
a. Connection con = DriverManager.setConnection(url,”myLogin”, “myPassword”);
a. Connection con = DriverManager.createConnection(url,”myLogin”, “myPassword”);
19. ResultSet objects follow index patterns of:
Answers:
a. Array standard
a. Java standard
a. RDBMS standard
a. C++ standard
a. PL/SQL 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:
a. executeQuery()
a. exceuteUpdate()
a. execute()
a. executeQueryUpdate()
a. update()
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:
a. ResultSet rs=cs.execute()
a. ResultSet rs=cs.executeQuery()
a. ResultSet rs=cs.executeUpdate()
a. ResultSet rs=cs.executeQuery(sql)
a. ResultSet rs=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:
a. Reuse the database connection and reuse PreparedStatement objects
a. Reuse the database connection and use PreparedStatement objects with synchronized blocks
a. Reuse the database connection only
a. Reuse the PreparedStatement objects only
a. Reuse the GetPreparedStatement objects only
23. Which of the following methods will you use to execute INSERT, UPDATE and DELETE SQL statements?
Answers:
a. executeQuery();
a. executeUpdate();
a. executeQueryUpdate();
a. update();
a. query();
24. How do you register a JDBC driver?
Answers:
a. Class.forName(“driver”);
a. Class.newInstance(“driver”);
a. Class.driver(“driver”);
a. Class.getDriver(“driver”);
a. Class.postDriver(“driver”);
25. Which of the following JDBC methods is used for retrieving large binary objects?
Answers:
a. getBinaryStream
a. getText
a. getAsciiStream
a. getString
a. getObjectStream
26. Name the interface you will use to retrieve the underlying structure of the query result:
Answers:
a. ResultSet
a. ResultSetMetaData
a. ResultStructure
a. Result
a. ResultMetaData
27. Which type of statement object will you use to execute a stored procedure?
Answers:
a. Statement
a. PreparedStatement
a. CallableStatement
a. StoredStatement
a. Stat
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:
a. getWarnings()
a. getWarned()
a. getWarning()
a. getError()
a. getErrorsWarning()
29. You have obtained a ResultSet object named ‘rs’ after executing the following query:
SELECT * FROM CUSTOMER
Which loop can you use to return all the records in the ResultSet?
Answers:
a. while(rs.next())
a. while(rs.hasNext())
a. while(true)
a. while(rs.nextElement())
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:
scrollrs.next();
scrollrs.absolute(-10);
scrollrs.relative(-6);
At which row number is the cursor currently located?
Answers:
a. 16
a. 24
a. 26
a. 17
a. 6
31. The code segment below defines a query:
String qry=”SELECT CUS_NAME, PRICE FROM CUSTOMER”;
Which of the following code snippets will create a scrollable ResultSet?
Answers:
a. Statement st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet srs=st.executeQuery(qry); 
a. Statement st=con.createStatement(qry,ResultSet.CONCUR_READ_ONLY,ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet srs=st.executeQuery();
a. Statement st=con.createStatement(qry,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet srs=st.executeQuery();
a. Statement st=con.createStatement(ResultSet.CONCUR_READ_ONLY,ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet srs=st.executeQuery(qry);
32. Which of the following is the syntax for creating a CallableStatement?
Answers:
a. CallableStatement cs=con.prepareCall(“{call SHOW_ORDER}”)
a. CallableStatement cs=con.prepareCall(‘{call SHOW_ORDER}’)
a. CallableStatement cs=con.prepareCall(“(call SHOW_ORDER)”)
a. CallableStatement cs=con.prepareCall(“call SHOW_ORDER”)
a. CallableStatement cs=prepareCall(“call SHOW_ORDER”)
33. Which of the following is not true?
Answers:
a. CallableStatement is a subclass of PreparedStatement
a. CallableStatement can take PreparedStatement as an input parameter
a. CallableStatement can use executeUpdate() method
a. CallableStatement can use execute() method
a. CallableStatement cannot take INOUT parameters
34. Which of the following is not true for a ResultSet?
Answers:
a. JDBC 2.0 API supports Scrollable ResultSets
a. ResultSet cursors are moved forward using next() method
a. ResultSet cursors are moved backwards using previous() method
a. Methods next() and previous() return -1 beyond the ResultSet
35. Java Database Connectivity (JDBC) is a:
Answers:
a. Database-dependent API
a. Database-independent API
a. Machine-dependent API
a. Network-dependent database API
36. Servlet developers should avoid using JDBC-ODBC bridge driver because:
Answers:
a. Drivers are bundled with JDK
a. The driver’s native code can crash the entire server
a. The driver is not secure
a. The driver is of Type-1
a. The driver is of Type-2
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:
a. srs.relative(-4)
a. srs.relative()
a. srs.absolute(-4)
a. srs.getRow()
a. srs.postRow()
38. A user leaves an online shopping cart without checking out. Which of following interfaces will notify to Rollback the transaction?
Answers:
a. HttpSession
a. HttpSessionBindingListener
a. HttpServlet
a. SingleThreadModel
a. FtpSession
39. After executing the following code, resultvar contains false. What should the next step be?
boolean resultvar=stmt.execute(sql);
Answers:
a. stmt.getResultSet();
a. stmt.getUpdateCount();
a. stmt.executeUpdate();
a. stmt.executeQuery();
a. stmt.executeUpdateQuery();
40. SQLException has a method, which provides the feature of chaining or encapsulation of additional Exception objects. Identify the method from the following:
Answers:
a. getEncapsulatedException()
a. getEncapException()
a. getMessage()
a. getNextException()
a. getException()
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:
a. By synchronizing the doPost() method
a. By creating a new connection for each transaction
a. By session tracking and using HttpSession to hold a connection for each user
a. By creating a single connection in the init() method and implementing SingleThreadModel
a. By synchronizing doGet ()
42. SQLWarning object deals with database access warnings. It is a subclass of:
Answers:
a. SQLWarn
a. SQLException
a. SQLError
a. SQLWarning
a. SQLErrorsWarning
43. Will the below script execute properly?
1.CREATE TABLE CUSTOMER
2.(
3.CUS_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, SALES INTEGER
4.)
Answers:
a. Yes. The table will be created successfully. 
a. No. Line 3 should be modified to: VARCHAR(32) CUS_NAME,INTEGER SUP_ID ,FLOAT PRICE , INTEGER SALES
a. No. Line 3 should be modified to: ‘CUS_NAME VARCHAR(32)’,’SUP_ID INTEGER’,’ PRICE FLOAT’, ‘SALES INTEGER’
a. No. Line 3 should be modified to: ‘CUS_NAME’ VARCHAR(32),’SUP_ID’ INTEGER,’PRICE’ FLOAT, ‘SALES’ INTEGER
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:
a. ClassNotFoundException
a. SQLException
a. SQLNotFoundException
a. ActivationException
a. JDBCException

No comments:

Post a Comment

Earn for Free

http://hiredrmjru.trade/3670784521590/