Tag: programming languages
Questions Related to programming languages
-
O (a) Type 1 driver
-
O (b) Type 2 driver
-
O (c) Type 3 driver
-
O (d) Type 4 driver
-
O (a) PreparedStatement
-
O (b) ParameterizedStatement
-
O (c) ParameterizedStatement and CallableStatement
-
O (d) All kinds of Statements (i.e. which implement a sub interface of Statement)
-
O (a) By invoking the method get (..., String type) on the ResultSet, where type is the database
-
O (b) By invoking the method get (..., Type type) on the ResultSet, where Type is an object
-
O (c) By invoking the method getValue (...), and cast the result to the desired java type.
-
O (d) By invoking the special getter methods on the ResultSet: getString (...), get Boolean (...),
To retrieve information from a ResultSet, the user needs to know the methods that can be used to access the data. A ResultSet is a table of data that represents the results of a database query.
Now let's go through each option and explain why it is right or wrong:
A. O (a) By invoking the method get (..., String type) on the ResultSet, where type is the database
This option is incorrect because there is no method get (..., String type) in ResultSet. The method get() can be used to retrieve data from the ResultSet, but it requires the index or the name of the column. The String type parameter is not valid.
B. O (b) By invoking the method get (..., Type type) on the ResultSet, where Type is an object
This option is incorrect because there is no method get (..., Type type) in ResultSet. The method get() can be used to retrieve data from the ResultSet, but it requires the index or the name of the column. The Type type parameter is not valid.
C. O (c) By invoking the method getValue (...), and cast the result to the desired java type.
This option is incorrect because there is no method getValue() in ResultSet. The method get() can be used to retrieve data from the ResultSet, but it requires the index or the name of the column. Additionally, the method get() returns an object that needs to be cast to the desired data type.
D. O (d) By invoking the special getter methods on the ResultSet: getString (...), get Boolean (...),
This option is correct. ResultSet provides special getter methods such as getString(), getInt(), getBoolean(), etc. that can be used to retrieve data from the ResultSet. These methods take the index or the name of the column as a parameter and return the value of the column as the desired data type.
The Answer is: D
-
O (a) By making use of the InsertStatement, DeleteStatement or UpdateStatement classes
-
O (b) By invoking the execute(...) or executeUpdate(...) method of a normal Statement object
-
O (c) By invoking the executeInsert(...), executeDelete(...) or executeUpdate(...) methods of
-
O (d) By making use of the execute(...) statement of the DataModificationStatement object
To execute DML statements (i.e. insert, delete, update) in the database, the user needs to know the methods or classes available to achieve this.
Option A is incorrect because there are no predefined classes in Java named InsertStatement, DeleteStatement or UpdateStatement for executing DML statements in a database.
Option B is correct. You can execute DML statements by invoking the execute() or executeUpdate() method of a normal Statement object. The execute() method is used for executing any type of SQL statement and can return a boolean value indicating whether the query returns a ResultSet or not. The executeUpdate() method is used for executing insert, delete, and update statements and returns an integer value representing the number of rows affected by the query.
Option C is incorrect because there are no predefined methods named executeInsert(), executeDelete() or executeUpdate() for executing DML statements in Java.
Option D is incorrect because there is no class named DataModificationStatement in Java.
Therefore, the correct answer is:
The Answer is: B
-
O (a) You must catch the checked SQLException which is thrown by the method which executes
-
O (b) You must catch the unchecked SQLWarningException which is thrown by the method
-
O (c) You must invoke the getWarnings() method on the Statement object (or a sub interface
-
O (d) You must query the ResultSet object about possible warnings generated by the database
To know in your Java program that a SQL warning is generated as a result of executing a SQL statement in the database, you must invoke the getWarnings() method on the Statement object (or a sub interface). Therefore, option C is the correct answer.
Option A is incorrect because SQLException is thrown when an SQL error occurs, not a warning. It is a checked exception and must be caught or declared to be thrown.
Option B is incorrect because SQLWarningException is not a valid exception class in Java. SQLWarning is the class that represents a warning issued by the database.
Option D is incorrect because ResultSet object is used to retrieve data from the database after executing a query, not to retrieve warnings.
Therefore, the correct answer is:
The Answer is: C. O (c) You must invoke the getWarnings() method on the Statement object (or a sub interface).
-
O (a) A DataSource is the basic service for managing a set of JDBC drivers
-
O (b) A DataSource is the Java representation of a physical data source
-
O (c) A DataSource is a registry point for JNDI-services
-
O (d) A DataSource is a factory of connections to a physical data source
-
O (a) This means that the ResultSet is insensitive to scrolling
-
O (b) This means that the Resultset is sensitive to scrolling, but insensitive to updates, i.e. not
-
O (c) This means that the ResultSet is sensitive to scrolling, but insensitive to changes made
-
O (d) The meaning depends on the type of data source, and the type and version of the driver
Are ResultSets updateable?
-
O (a) Yes, but only if you call the method openCursor() on the ResultSet, and if the driver and
-
O (b) Yes, but only if you indicate a concurrency strategy when executing the statement, and
-
O (c) Yes, but only if the ResultSet is an object of class UpdateableResultSet, and if the driver
-
O (d) No, ResultSets are never updateable. You must explicitly execute DML statements (i.e.
To answer this question, the user needs to have knowledge about ResultSets and their characteristics.
Option A is incorrect because there is no openCursor() method in the ResultSet class.
Option B is partially correct. The ResultSet object is updateable only if you indicate a concurrency strategy when executing the statement, and the driver supports updateable ResultSets.
Option C is incorrect because there is no class called UpdateableResultSet in the Java API.
Option D is incorrect because ResultSets can be updateable, but it depends on the driver, the type of ResultSet, and the concurrency strategy used.
Therefore, the correct answer is:
The Answer is: B
-
[_] [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.
-
O (a) By asking a Transaction object to your Connection, and calling the method begin() on it
-
O (b) By asking a Transaction object to your Connection, and setting the autoCommit property
-
O (c) By calling the method beginTransaction() on the Connection object
-
O (d) By setting the autoCommit property of the Connection to false, and execute a statement