Junior — Middle
What types of connection states are you aware of in JDBC?
sobes.tech AI
Answer from AI
In JDBC, several types of connection states to the database can be distinguished:
- Open (Active) — the connection is established and ready to execute SQL queries.
- Closed — the connection is closed, and attempting to use it will result in an error.
- Auto-commit mode — a mode where each SQL query is automatically committed after execution.
- Transactional state — when auto-commit is disabled, the connection is in a state waiting for commit or rollback.
Additionally, states related to connection pooling can be noted:
- Idle — the connection in the pool is not in use.
- In use — the connection has been issued to an application and is active.
To check the connection state, you can use the isClosed() method of the Connection object.