Interacting With Database
Interacting With Database
1. What is JDBC?
a. Java DataBase Connection
b. Java DataBase Configuration
c. Java DataBase Class
d. Java DataBase Code
Answer: a
9. How can you retrieve the number of rows affected by an SQL statement?
a. Using execute()
b. Using executeUpdate()
c. Using executeQuery()
d. Using executeBatch()
Answer: b
16. Which method is used to retrieve the data type of a column in ResultSet?
a. getType()
b. getColumnType()
c. getMetaData()
d. getColumnMetadata()
Answer: c
17. How can you insert data into a database using JDBC?
a. Using the INSERT statement
b. Using a PreparedStatement
c. Both a and b
d. None of the above
Answer: c
18. Which interface provides metadata about the database?
a. DatabaseMetaData
b. ResultSetMetaData
c. Connection
d. DriverManager
Answer: a
25. Which of the following methods is used to retrieve a String from ResultSet?
a. getString()
b. retrieveString()
c. fetchString()
d. readString()
Answer: a
26. Which of the following exceptions is thrown when a database access error occurs?
a. SQLException
b. IOException
c. NullPointerException
d. ClassNotFoundException
Answer: a
31. Which of the following is a valid SQL query to select all columns from a table named
"employees"?
a. SELECT * FROM employees
b. GET * FROM employees
c. FIND * IN employees
d. ALL FROM employees
Answer: a
41. How do you ensure that a database connection is not left open?
a. Use a finally block to close it
b. Use a static method
c. Ignore it
d. Close it manually
Answer: a
42. Which of the following methods can be used to read a boolean value from ResultSet?
a
. getBoolean()
b. retrieveBoolean()
c. readBoolean()
d. fetchBoolean()
Answer: a
47. Which method can be used to retrieve the first column of the first row in a ResultSet?
a. getFirst()
b. getObject()
c. getColumn(1)
d. get(1)
Answer: b