Machine-translated by Google. Questions are authored in English.
Top

JDBC, Java Server Pages, and MySQL Questions and Answers

1.

Which Servlet life-cycle method is called only once ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: A

The keyed answer is init().

The servlet container calls init() exactly once, after it creates the servlet object and before the first request, to let the servlet set itself up. service() (the printed option reads services()) and the handlers doGet() and doPost() run once for every request.

One caution: destroy() is also called only once, when the container removes the servlet. The question does not exclude it, but the key and the usual textbook answer to 'called only once' is init(), the one-time initialisation method, so that is the answer given.

Please log in or register to report this question.

2.

When a servlet cannot be instantiated by the servlet container, which exception is thrown to the servlet container methods such as init() or service() ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: D

The answer is None of these.

In the Servlet API, the life-cycle methods signal failure with ServletException and its subclass UnavailableException, which tells the container that the servlet cannot be put into service, temporarily or permanently. Neither is offered.

InstantiationException is a general Java reflection exception raised when a class cannot be instantiated; it is not what init() or service() throw. ServletInitializationException is not a class in the Servlet API. IllegalStateException is thrown when a method is called at the wrong time, for example sending a redirect after the response has been committed.

Please log in or register to report this question.

3.

How many JDBC driver types does Sun define?

Answer: D

Correct answer: Four

Sun defines four types. Type 1 is the JDBC-ODBC bridge; Type 2 calls the DBMS’s own native API through a client library; Type 3 talks to a middleware server in a network protocol; and Type 4 is pure Java speaking the DBMS protocol directly. The numbering runs from most dependent on native code to least.

Please log in or register to report this question.

Answer: C

Correct answer: In the MySQL database mysql

MySQL keeps its own catalogue in a database called mysql, which holds the user accounts, privileges and other server metadata. It is an ordinary database and can be queried like any other, which is how privileges are inspected, though they are normally changed through GRANT rather than by writing to the tables directly.

Please log in or register to report this question.

Answer: C

Correct answer: Sun

Java was developed at Sun Microsystems, released in 1995, and the language, the virtual machine and the JDBC specification all came from there. Sun was acquired by Oracle in 2010, which is why current Java documentation carries Oracle’s name.

Please log in or register to report this question.

6.

To run a compiled Java program, the machine must have what loaded and running?

Answer: A

Correct answer: Java virtual machine

Compilation produces bytecode rather than machine code, and bytecode is not executable by any processor directly. The Java virtual machine reads it and executes it, and it is the JVM that differs from platform to platform while the bytecode does not - which is the whole of the write once, run anywhere claim.

Please log in or register to report this question.

7.

Which JDBC driver Type(s) can be used in either applet or servlet code?

Answer: C

Correct answer: Both Type 3 and Type 4

Applets and servlets both need a driver that can work over a network without native code installed on the machine. Type 3 speaks to a middleware server and Type 4 speaks the DBMS protocol directly, and both are pure Java. Types 1 and 2 depend on ODBC or a native client library being present locally, which an applet cannot assume.

Please log in or register to report this question.

8.

________ is an open source DBMS product that runs on UNIX, Linux and Windows.

Answer: A

Correct answer: MySQL

MySQL is the open source relational DBMS that runs on Unix, Linux and Windows alike, and it is the database half of the LAMP stack. Its portability comes from the same source as Java’s: the server is built for each platform while the SQL and the client protocol stay the same.

Please log in or register to report this question.

9.

What is sent to the user via HTTP, invoked using the HTTP protocol on the user's computer, and run on the user's computer as an application?

Answer: B

Correct answer: A Java applet

An applet is bytecode downloaded to the browser over HTTP and executed on the user’s machine within the JVM the browser provides. A servlet is the counterpart running on the server, and an ordinary Java application is launched locally and involves no HTTP at all.

Please log in or register to report this question.

10.

What MySQL property is used to create a surrogate key in MySQL?

 

Answer: C

Correct answer: AUTO_INCREMENT

Declaring an integer column AUTO_INCREMENT makes MySQL assign the next value on each insert, which is the standard way of creating a surrogate key. Oracle of the same era had no such property and needed a sequence with a trigger instead - a difference worth remembering when porting a schema.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: JDBC, Java Server Pages, and MySQL Questions and Answers || JDBC, Java Server Pages, and MySQL MCQ Questions and Answers || JDBC, Java Server Pages, and MySQL GK Questions and Answers || JDBC, Java Server Pages, and MySQL GK MCQ Questions || JDBC, Java Server Pages, and MySQL Multiple Choice Questions and Answers || JDBC, Java Server Pages, and MySQL GK || GK on JDBC, Java Server Pages, and MySQL || Database Questions and Answers || Database MCQ Questions and Answers || Database GK Questions and Answers || GK on Database