Govt. Exams
Entrance Exams
<T> is the standard syntax for declaring a generic type parameter in Java classes.
Generics enable type safety at compile time and eliminate the need for explicit type casting, reducing runtime errors.
The Statement interface is used to execute SQL queries. Connection creates the statement, Driver manages connections, and DataSource provides connection pooling, but Statement is the actual executor.
commit() permanently saves all changes made during the transaction, while rollback() discards all changes and reverts to the previous state.
When Class.forName() cannot locate the driver class, it throws ClassNotFoundException, indicating the driver JAR is not in the classpath.
addBatch() and executeBatch() methods allow multiple SQL statements to be grouped and executed together, reducing network traffic and improving performance.
setAutoCommit(false) disables auto-commit mode, allowing manual control over transactions through commit() and rollback() methods.
The correct JDBC connection sequence is: Class.forName() → DriverManager.getConnection() → Create Statement → Execute Query → Close resources.
PreparedStatement is used for parameterized queries with placeholders (?), which prevents SQL injection by separating SQL logic from data.
executeQuery() returns a ResultSet containing the rows fetched from the database for SELECT queries.