JDBC Interviewfragen und Antworten
Question: What does setAutoCommit do?Answer: When a connection is created, it is in auto-commit mode. This means that each individual SQL statement is treated as a transaction and will be automatically committed right after it is executed. The way to allow two or more statements to be grouped into a transaction is to disable auto-commit mode:con.setAutoCommit(false); Once auto-commit mode is disabled, no SQL statements will be committed until you call the method commit explicitly. con.setAutoCommit(false); PreparedStatement updateSales = con.prepareStatement( "UPDATE EMPLOYEE SET SAL = ? WHERE EMP_NAME LIKE ?"); updateSales.setInt(1, 50000); updateSales.setString(2, "Arindam"); updateSales.executeUpdate(); PreparedStatement updateTotal = con.prepareStatement("UPDATE EMPLOYEE SET TOTAL = TOTAL + ? WHERE EMP_NAME LIKE ?"); updateTotal.setInt(1, 50000); updateTotal.setString(2, "Arindam"); updateTotal.executeUpdate(); con.commit(); con.setAutoCommit(true); |
Zum Wiederholen speichern
Speichere diesen Eintrag als Lesezeichen, markiere ihn als schwierig oder lege ihn in einem Wiederholungsset ab.
Melde dich an, um Lesezeichen, schwierige Fragen und Wiederholungssets zu speichern.
Ist das hilfreich? Ja Nein
Am hilfreichsten laut Nutzern:
- What is JDBC? Describe the steps needed to execute a SQL query using JDBC.
- What are the steps involved in establishing a JDBC connection?
- Is JDBC-ODBC bridge multi-threaded?
- Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?
- What are the different driver types available in JDBC?