Skip to main content

Important Web Design and Development Short Questions

Chapter: 15
Question 1:
How can you update records in a database using executeUpdate()?
Answer: To update records, prepare an SQL UPDATE statement and execute it using the executeUpdate() method. For example, stmt.executeUpdate("UPDATE Person SET address = 'new_address' WHERE name = 'person_name'") updates specific records.
Chapter: 15
Question 2:
What is the purpose of setMaxRows(int) in JDBC?
Answer: The setMaxRows(int) method sets the maximum number of rows that a ResultSet can contain. By default, the number is unlimited (0), but you can specify a limit to control the number of rows returned by a query.
Chapter: 15
Question 3:
How does getQueryTimeout(int) function in JDBC?
Answer: The getQueryTimeout(int) method specifies the number of seconds the driver will wait for a statement to execute before throwing a SQLException. If the timeout is exceeded, an exception is raised.
Chapter: 15
Question 4:
What are the three types of Statement objects in JDBC?
Answer: The three types of Statement objects in JDBC are: 1) Statement for executing simple SQL queries, 2) PreparedStatement for executing precompiled SQL statements with parameters, and 3) CallableStatement for executing stored procedures.
Chapter: 15
Question 5:
How does PreparedStatement differ from Statement?
Answer: PreparedStatement is used for executing precompiled SQL statements with parameters. It allows setting parameters dynamically, improves performance for repeated queries, and provides better security against SQL injection compared to Statement.
Chapter: 15
Question 6:
How do you create a PreparedStatement object in JDBC?
Answer: Create a PreparedStatement by calling con.prepareStatement(sql) where sql is a SQL query string with placeholders (?) for parameters. Set the parameter values using setter methods like setString() and setInt().
Chapter: 15
Question 7:
How can you execute an UPDATE statement using PreparedStatement?
Answer: Use PreparedStatement to execute an UPDATE statement by first creating a PreparedStatement object with the query, setting parameter values using methods like setString(), and then calling executeUpdate() to perform the update.
Chapter: 15
Question 8:
What is the role of Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") in JDBC?
Answer: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") loads the JDBC-ODBC bridge driver necessary for connecting to databases using the JDBC-ODBC driver. This driver must be loaded before establishing a database connection.
Chapter: 15
Question 9:
What must be done to ensure database changes are saved when using JDBC?
Answer: Changes made by DML statements must be committed to the database to be saved permanently. By default, JDBC commits changes automatically, but you can manage this behavior by setting auto-commit to false and explicitly calling commit().
Chapter: 15
Question 10:
How is exception handling implemented in JDBC operations?
Answer: JDBC operations are surrounded by a try-catch block to handle SQLException and other exceptions. This ensures that any issues encountered during database interactions are caught and handled gracefully, preventing the application from crashing.