0% found this document useful (0 votes)
20 views6 pages

Java JDBC Quiz: Code Snippets & Answers

The document contains a quiz focused on Java and JDBC concepts, featuring questions about PreparedStatement, access modifiers, HashMap, JSP, servlets, and JDBC methods. Each question includes multiple-choice answers, with the correct answers highlighted. The quiz serves as a learning tool for assessing knowledge in Java programming and database connectivity.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views6 pages

Java JDBC Quiz: Code Snippets & Answers

The document contains a quiz focused on Java and JDBC concepts, featuring questions about PreparedStatement, access modifiers, HashMap, JSP, servlets, and JDBC methods. Each question includes multiple-choice answers, with the correct answers highlighted. The quiz serves as a learning tool for assessing knowledge in Java programming and database connectivity.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java & JDBC Quiz with Code Snippets

and Answers
1. 1. What do the '?' symbols represent in a PreparedStatement?

PreparedStatement ps = [Link]("INSERT INTO table_name VALUES


(?, ?)");

 Wildcards for any value.


 **Placeholders for input values.**
 Indications of a syntax error.
 Symbols to denote optional values.

2. 2. Which of the following is not an access modifier in Java?

 public
 protected
 private
 **restricted**

3. 3. What will be the output of "[Link](2)"?

HashMap<Integer, String> map = new HashMap<>();


[Link](1, "One");
[Link](2, "Two");
[Link](3, "Three");

 Red
 **Two**
 Blue
 Null

4. 4. How can you include a file, say "[Link]", in a JSP page?

 <jsp:insert file="[Link]" />


 <jsp:add page="[Link]" />
 <jsp:include file="[Link]" />
 **<jsp:include page="[Link]" />**

5. 5. What will be displayed when this Servlet is accessed through a browser?

protected void doGet(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
[Link]("<h2>Welcome to Servlets</h2>");
}

 Welcome
 **Welcome to Servlets**
 An error message
 The current date and time

6. 6. Where would you typically place your Servlet classes in a Dynamic Web Project in
Eclipse?

 /WebContent
 **/src**
 /lib
 /META-INF

7. 7. Which expression correctly retrieves the value of a form input named "username"?

 ${[Link]}
 ${[Link]}
 <%= [Link]("username") %>
 **Both A and C**

8. 8. Which of the following is the most appropriate to use to insert a new record using
JDBC?

 Statement
 **PreparedStatement**
 ResultSet
 DriverManager

9. 9. Which annotation is used to map a servlet to a specific URL?

 @WebServletMapping
 @WebServletURL
 **@WebServlet**
 @URLServletMapping

10. 10. Which JSP scripting element evaluates a Java expression and inserts its value into
the output?

 **JSP Expression**
 JSP Scriptlet
 JSP Declaration
 JSP Comment
11. 11. In [Link](1, 2); what does "1" represent?

 The column number in the database table.


 The value to be inserted.
 **The first parameter in the SQL query.**
 The data type of the value.

12. 12. Which of the following is not a lifecycle method of a servlet?

 init()
 service()
 **start()**
 destroy()

13. 13. How to fetch the value of the second column as a String from ResultSet "rs"?

 **[Link](2);**
 [Link]("column_name");
 [Link](2);
 [Link](2);

14. 14. What does [Link]() do in JDBC?

 Executes an SQL query.


 Establishes a database connection.
 **Loads the JDBC driver class.**
 Fetches results from a database table.

15. 15. What does ResultSet represent in JDBC?

 A table in the database.


 A single row of data.
 **The result of a SELECT query.**
 A database connection string.

16. 16. What must be unique in a Java HashMap?

 Values
 **Keys**
 Both keys and values
 Neither keys nor values

17. 17. When is a method said to be overloaded?

 When defined in both superclass and subclass.


 When it exists in multiple classes in the same package.
 **When there are multiple methods in a class with the same name but different
parameters.**
 When a method has more than one return type.

18. 18. Which keyword is used in Java to derive a class from another class?

 imports
 implements
 **extends**
 inherits

19. 19. Which method is used to execute SQL that doesn't return data (e.g. INSERT, UPDATE,
DELETE)?

 executeQuery()
 execute()
 **executeUpdate()**
 executelnsert

20. 20. Which method is used to execute a SELECT query in JDBC?

 executelnsert()
 execute
 executeUpdate()
 **executeQuery()**

21. 21. What will the 'rs' object contain after executing 'SELECT * FROM Students'?

Statement stmt = [Link]();


ResultSet rs = [Link]("SELECT * FROM Students");

 The first row of the Students table.


 **All rows from the Students table.**
 The SQL query as a string.
 The metadata of the Students table.

22. 22. Which class in Java Collection Framework provides a dynamic array?

 HashSet
 LinkedList
 Array
 **ArrayList**

23. 23. What happens when calling display(10, 20) on overloaded methods?

void display(int a, double b) { [Link]("A"); }


void display(double a, int b) { [Link]("B"); }

 A
 B
 Both A and B
 **Compilation error due to ambiguity**

24. 24. Which directive is used to import a Java class into a JSP page?

 <% import [Link]; %>


 <jspimport class="[Link]" />
 **<%@ page import="[Link]" %>**
 <include class="[Link]" />

25. 25. Which JSP scripting element allows defining methods or variables usable throughout
the page?

 JSP Expression
 JSP Scriptlet
 **JSP Declaration**
 JSP Comment

26. 26. Which servlet method is called when a form uses GET method?

 **doGet()**
 doPost()
 doExecute()
 doRequest()

27. 27. In a Java HashMap, what must be unique?

 Values
 **Keys**
 Both keys and values
 Neither keys nor values

28. 28. What is the output of this code?

try {
[Link](10/0);
} catch (ArithmeticException e) {
[Link]("Arithmetic Exception Caught");
}

 10/0
 An unhandled exception message
 **Arithmetic Exception Caught**
 No output

29. 29. Which keyword is used in Java to inherit a class?


 inherits
 implements
 **extends**
 instanceof

30. 30. Which method is called in a servlet when a GET request is received?

 **doGet()**
 doPost()
 init()
 destroy()

You might also like