Important Web Design and Development Short Questions
Chapter: 14
Question 1:
How do you load a driver for Microsoft Access in JDBC?
Answer:
Use Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") to load the JDBC-ODBC bridge driver for Microsoft Access.
Chapter: 14
Question 2:
What is a Connection URL in JDBC, and how is it formatted for Microsoft Access?
Answer:
The Connection URL specifies the address of the database. For Microsoft Access using JDBC-ODBC, the URL format is jdbc:odbc:personDSN, where personDSN is the name of the Data Source Name you configured.
Chapter: 14
Question 3:
How do you establish a connection with a database using JDBC?
Answer:
Use DriverManager.getConnection(conURL) where conURL is the connection URL. If authentication is required, use DriverManager.getConnection(conURL, usr, pwd) with the username (usr) and password (pwd).
Chapter: 14
Question 4:
What is the purpose of a Statement object in JDBC?
Answer:
A Statement object is used to execute SQL queries against the database. It allows you to create and execute SQL statements, including SELECT, INSERT, UPDATE, and DELETE queries.
Chapter: 14
Question 5:
How do you execute a SELECT query in JDBC?
Answer:
Use the executeQuery(sql) method of the Statement object to execute a SELECT query. It returns a ResultSet object containing the results of the query.
Chapter: 14
Question 6:
How can you process the results of a SQL query using JDBC?
Answer:
Iterate through the ResultSet using the next() method to move through the rows. Use getXXX methods (e.g., getString(), getInt()) to retrieve column data for each row.
Chapter: 14
Question 7:
Why should you close the database connection in JDBC?
Answer:
Closing the connection is important to free up database resources and avoid potential memory leaks. It should be done when no further database operations are needed.
Chapter: 14
Question 8:
What should you do if an exception occurs during a JDBC operation?
Answer:
Exceptions should be caught and handled using a try-catch block. This ensures that any errors related to database operations are managed properly, preventing the application from crashing.
Chapter: 14
Question 9:
How does an anonymous inner class differ from a named inner class in Java?
Answer:
An anonymous inner class does not have a name and is used for one-time use, whereas a named inner class has a name and can be used multiple times. Anonymous inner classes are often used for short, simple implementations.
Chapter: 15
Question 10:
What does the executeUpdate() method do in JDBC?
Answer:
The executeUpdate() method is used to execute SQL DML statements such as INSERT, UPDATE, and DELETE. It also supports some DDL statements like CREATE TABLE and ALTER TABLE. It returns the number of rows affected by the operation.