Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

476 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 141–150 of 476
Topics in Java Programming
Q.141 Medium JDBC
Consider a scenario where a developer uses getConnection() without closing it. What is the potential impact?
A Database performance remains unaffected
B Connection leak occurs, exhausting available database connections
C Automatic rollback happens
D Query execution becomes slower temporarily
Correct Answer:  B. Connection leak occurs, exhausting available database connections
EXPLANATION

Unclosed connections remain allocated and unavailable for other operations, eventually exhausting the connection pool and causing connection exhaustion errors.

Take Test
Q.142 Medium JDBC
What is the purpose of Connection pooling in JDBC applications?
A To store query results temporarily
B To reuse database connections instead of creating new ones each time
C To encrypt database connections
D To monitor database performance
Correct Answer:  B. To reuse database connections instead of creating new ones each time
EXPLANATION

Connection pooling maintains a pool of reusable connections, reducing the overhead of creating new connections for each request, improving application performance.

Take Test
Q.143 Medium JDBC
A developer needs to execute a query that returns multiple result sets. Which Statement type should be used?
A Statement with executeQuery()
B PreparedStatement with setFetchSize()
C Statement with execute() or PreparedStatement with execute()
D CallableStatement only
Correct Answer:  C. Statement with execute() or PreparedStatement with execute()
EXPLANATION

The execute() method returns a boolean and can handle multiple result sets via getResultSet(), getUpdateCount(), and getMoreResults() methods.

Take Test
Q.144 Medium JDBC
Which JDBC driver type is considered the most portable across different databases?
A Type 1 - JDBC-ODBC Bridge
B Type 2 - Native API Driver
C Type 3 - Network Protocol Driver
D Type 4 - Thin Driver
Correct Answer:  D. Type 4 - Thin Driver
EXPLANATION

Type 4 drivers are pure Java implementations that directly communicate with the database, making them platform-independent and most portable.

Take Test
Q.145 Medium JDBC
What happens if you call next() on a ResultSet after the last row?
A Throws SQLException
B Returns false
C Returns true
D Throws NoSuchElementException
Correct Answer:  B. Returns false
EXPLANATION

next() returns false when the cursor is positioned beyond the last row, indicating no more rows available.

Take Test
Q.146 Medium JDBC
Which statement should be used when you need to retrieve column information without executing multiple queries?
A Statement with multiple executeQuery()
B PreparedStatement
C ResultSetMetaData
D DatabaseMetaData
Correct Answer:  C. ResultSetMetaData
EXPLANATION

ResultSetMetaData provides column information directly from the ResultSet without additional queries.

Take Test
Q.147 Medium JDBC
What is the difference between execute() and executeUpdate() methods?
A execute() returns boolean, executeUpdate() returns int
B execute() can execute any SQL statement, executeUpdate() only for DML
C Both A and B are correct
D There is no difference
Correct Answer:  C. Both A and B are correct
EXPLANATION

execute() returns true/false and handles any SQL, while executeUpdate() returns affected rows count for DML statements only.

Take Test
Q.148 Medium JDBC
In JDBC, which class is used to retrieve database metadata information?
A ResultSet
B Statement
C DatabaseMetaData
D Connection
Correct Answer:  C. DatabaseMetaData
EXPLANATION

DatabaseMetaData provides information about the database, tables, columns, and other database properties.

Take Test
Q.149 Medium JDBC
What does ResultSetMetaData.getColumnCount() return?
A Number of rows in ResultSet
B Number of columns in ResultSet
C Column data type
D Column name
Correct Answer:  B. Number of columns in ResultSet
EXPLANATION

getColumnCount() returns the total number of columns present in the ResultSet.

Take Test
Q.150 Medium JDBC
What is the benefit of using PreparedStatement over Statement for repeated queries?
A Faster execution due to pre-compilation
B Automatic SQL injection prevention
C Better readability of code
D Both A and B
Correct Answer:  D. Both A and B
EXPLANATION

PreparedStatement offers both pre-compilation for performance and SQL injection prevention through parameterized queries.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips