Do you know that? 38% freelancers want to open a small business next

Contact Email:

<< All Upwork (oDesk) and Elance Tests << Upwork (oDesk) test answers << Java Technologies category

Test answers for JDBC 2.1 Test 2020

(44) Last updated: June 29
Upwork (oDesk) • Java Technologies
Questions and answers are regularly updated. Answered and not answered tests questions.

This helps getting job: Hundreds of (cover letter examples , interview questions , profile samples ) • Earn on Upwork (oDesk)
Job assistance: jobs popularityfreelance rates

Popular test answers: HTML, .Net, CSS, English, SEO, Photoshop, iOS, Java, Android, Ruby, Python, JavaScript

See all 6 tests answers updated

Find Upwork (oDesk) and Elance test answers on this website:

Collapse | Expand

44 Answered Test Questions:

1. Under which category does the following driver fall:

WebLogic's Tengah "all Java Type-3 driver"


• JDBC-ODBC Bridge Driver

• Native-API Partly-Java Driver

• Net-Protocol All-Java Driver

• Native-Protocol All-Java Driver

• Native-Protocol Part-Java Driver

2. Which JDBC driver is considered best in terms of performance and efficiency?


• Type-1 Driver

• Type-2 Driver

• Type-3 Driver

• Type-4 Driver

3. Please select all the correct options. JDBC Driver Manager is:


• Able to activate registered drivers

• Able to activate unregistered drivers

• Not required for activation of drivers with DataSource

• 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?


• ps.clearParameters(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate(sql);

• ps.clearParameters(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate();

• ps.clear(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate(sql);

• ps.clearParameters(); ps.setInt(1,3.09); ps.setDouble(2,790.50); ps.execute(sql);

• 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?


• con.setAutoCommit(false);

• con.setCommit(false);

• con.setAutoCommit();

• con.setAutoCommit(true);

• 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?


• jdbc:odbc:webx:webdsn

• odbc:jdbc:webx:webdsn

• jdbc:webx:webdsn

• thin:jdbc:odbc:dsn:webdsn

• thick:jdbc:odbc:dsn:webdsn

• None of the above

7. You have to handle an erroneous situation in a transaction. Which method comes handy in this case?


• con.commit(false);

• con.commit();

• con.rollback();

• con.revertback();

• con.rollback(true);

8. How will you create a new instance of a JDBC driver explicitly?


• Class.forName("driver");

• Class.newInstance("driver");

• Class.driver("driver");

• Class.getDriver("driver");

• Class.forName("driver").newInstance();

9. JDBC is based on:


• X/Open CLI (Call Level Interface)


• Java/Open CLI


• X/Close CLI

10. You are developing a shopping cart for your client. Where would you like to put your business logic?


• Inside the database

• Inside the client application

• In middleware servlets

• In COM / DCOM components

• 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?


• Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query);

• Statement stmt=new Statement(); ResultSet rs=stmt.executeQuery(query);

• Statement stmt=con.createStatement(); ResultSet rs=stmt.execute(query);

• Statement stmt=con.getStatement(); ResultSet rs=stmt.executeQuery(query);

• 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?


• ActivationException

• ClassNotFoundException

• ClassNotAvailableException

• ClassUnavailableException

• 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:


• Binding

• Synchronization

• Registry

• Transaction

• Late binding

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


• getBinaryStream

• getText

• getAsciiStream

• getString

• getObjectStream

15. Open Database Connectivity is:


• Platform independent

• Platform dependent

• Architecture neutral

• Network independent

• Machine independent

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


• getObject();

• getInt();

• getString();

• getFloat();

• getNull();

17. Transactions have a property called atomicity, which means:


• Everything takes place one by one

• Everything takes place once

• Everything takes place randomly

• Everything takes place twice

• Everything takes place thrice

18. What should the syntax be to establish a connection with a Database?


• Connection con = DriverManager.getConnection(url,"myLogin", "myPassword");

• Connection con = DriverManager.getConnection("myLogin", "myPassword",url);

• Connection con = DriverManager.getConnection("myLogin", "myPassword");

• Connection con = DriverManager.setConnection(url,"myLogin", "myPassword");

• Connection con = DriverManager.createConnection(url,"myLogin", "myPassword");

19. ResultSet objects follow index patterns of:


• Array standard

• Java standard

• RDBMS standard

• C++ standard

• 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?


• executeQuery()

• exceuteUpdate()

• execute()

• executeQueryUpdate()

• 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?


• ResultSet rs=cs.execute()

• ResultSet rs=cs.executeQuery()

• ResultSet rs=cs.executeUpdate()

• ResultSet rs=cs.executeQuery(sql)

• 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?


• Reuse the database connection and reuse PreparedStatement objects

• Reuse the database connection and use PreparedStatement objects with synchronized blocks

• Reuse the database connection only

• Reuse the PreparedStatement objects only

• Reuse the GetPreparedStatement objects only

23. Which of the following methods will you use to execute INSERT, UPDATE and DELETE SQL statements?


• executeQuery();

• executeUpdate();

• executeQueryUpdate();

• update();

• query();

24. How do you register a JDBC driver?


• Class.forName("driver");

• Class.newInstance("driver");

• Class.driver("driver");

• Class.getDriver("driver");

• Class.postDriver("driver");

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


• getBinaryStream

• getText

• getAsciiStream

• getString

• getObjectStream

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


• ResultSet

• ResultSetMetaData

• ResultStructure

• Result

• ResultMetaData

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


• Statement

• PreparedStatement

• CallableStatement

• StoredStatement

• 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:


• getWarnings()

• getWarned()

• getWarning()

• getError()

• getErrorsWarning()

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?


• while(

• while(rs.hasNext())

• while(true)

• 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:;

At which row number is the cursor currently located?


• 16

• 24

• 26

• 17

• 6

31. The code segment below defines a query:


Which of the following code snippets will create a scrollable ResultSet?


• Statement st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet srs=st.executeQuery(qry);

• Statement st=con.createStatement(qry,ResultSet.CONCUR_READ_ONLY,ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet srs=st.executeQuery();

• Statement st=con.createStatement(qry,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet srs=st.executeQuery();

• 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?


• CallableStatement cs=con.prepareCall("{call SHOW_ORDER}")

• CallableStatement cs=con.prepareCall('{call SHOW_ORDER}')

• CallableStatement cs=con.prepareCall("(call SHOW_ORDER)")

• CallableStatement cs=con.prepareCall("call SHOW_ORDER")

• CallableStatement cs=prepareCall("call SHOW_ORDER")

33. Which of the following is not true?


• CallableStatement is a subclass of PreparedStatement

• CallableStatement can take PreparedStatement as an input parameter

• CallableStatement can use executeUpdate() method

• CallableStatement can use execute() method

• CallableStatement cannot take INOUT parameters

34. Which of the following is not true for a ResultSet?


• JDBC 2.0 API supports Scrollable ResultSets

• ResultSet cursors are moved forward using next() method

• ResultSet cursors are moved backwards using previous() method

• Methods next() and previous() return -1 beyond the ResultSet

35. Java Database Connectivity (JDBC) is a:


• Database-dependent API

• Database-independent API

• Machine-dependent API

• Network-dependent database API

36. Servlet developers should avoid using JDBC-ODBC bridge driver because:


• Drivers are bundled with JDK

• The driver's native code can crash the entire server

• The driver is not secure

• The driver is of Type-1

• 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?


• srs.relative(-4)

• srs.relative()

• srs.absolute(-4)

• srs.getRow()

• srs.postRow()

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


• HttpSession

• HttpSessionBindingListener

• HttpServlet

• SingleThreadModel

• FtpSession

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

boolean resultvar=stmt.execute(sql);


• stmt.getResultSet();

• stmt.getUpdateCount();

• stmt.executeUpdate();

• stmt.executeQuery();

• 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:


• getEncapsulatedException()

• getEncapException()

• getMessage()

• getNextException()

• 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?


• By synchronizing the doPost() method

• By creating a new connection for each transaction

• By session tracking and using HttpSession to hold a connection for each user

• By creating a single connection in the init() method and implementing SingleThreadModel

• By synchronizing doGet ()

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


• SQLWarn

• SQLException

• SQLError

• SQLWarning

• SQLErrorsWarning

43. Will the below script execute properly?



• Yes. The table will be created successfully.

• No. Line 3 should be modified to: VARCHAR(32) CUS_NAME,INTEGER SUP_ID ,FLOAT PRICE , INTEGER SALES

• No. Line 3 should be modified to: 'CUS_NAME VARCHAR(32)','SUP_ID INTEGER',' PRICE FLOAT', 'SALES INTEGER'

• 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?


• ClassNotFoundException

• SQLException

• SQLNotFoundException

• ActivationException

• JDBCException