Entrance Exams
Govt. Exams
PreparedStatement offers faster execution due to precompilation and prevents SQL injection through parameterized queries using placeholders (?).
PreparedStatement is used for precompiled SQL statements with parameters. It provides better performance and prevents SQL injection compared to Statement.
executeUpdate() returns an integer representing the number of rows affected by INSERT, UPDATE, or DELETE operations. executeQuery() returns ResultSet.
getString() method retrieves String values from ResultSet. getInt() gets integer values, and fetchString/readString are not valid JDBC methods.
SQLException is thrown for database-related errors including connection failures. ClassNotFoundException occurs when JDBC driver class is not found.
Type 4 (Thin) drivers are pure Java drivers, platform-independent, and don't require native code. They communicate directly with database using Java sockets.
The correct JDBC sequence is: 1) Load the JDBC driver, 2) Create connection, 3) Create statement, 4) Execute query, 5) Process results, 6) Close resources.
Statement interface is used to execute SQL queries. Connection is used to establish database connection, ResultSet holds query results, and Driver manages database connections.
FileOutputStream is NOT thread-safe. When multiple threads write simultaneously, race conditions can cause data corruption or interleaved writes. Solutions include: synchronizing access using synchronized blocks, using thread-safe wrapper classes, or employing a single-threaded writer pattern with a queue. PrintWriter with autoFlush provides some buffering protection.
Serializable is a marker interface (contains no methods) that signals to the JVM that objects of that class can be serialized. The absence of abstract methods means implementing classes don't need to override any methods; they just need to implement the interface to indicate serialization support.