- A Connection is the session between java application and database. The Connection interface is a factory of Statement, PreparedStatement, and DatabaseMetaData i.e. object of Connection can be used to get the object of Statement and DatabaseMetaData. By default, connection commits the changes after executing queries.
The Connection interface provide many methods for transaction management like commit(),rollback() etc.
Commonly used methods of Connection interface are:
- public Statement createStatement(): creates a statement object that can be used to execute SQL queries.
- public Statement createStatement(int resultSetType, int resultSetConcurrency): Creates a Statement object that will generate ResultSet objects with the given type and concurrency.
- public void setAutoCommit(boolean status): is used to set the commit status. By default it is true.
- public void commit(): saves the changes made since the previous commit/rollback permanent.
- public void rollback(): Drops all changes made since the previous commit/rollback.
- public void close(): closes the connection and Releases a JDBC resources immediately.
For example of connections follow below links:
- 5 JDBC Steps to Connect with Database
- JDBC: Connection With Oracle Database
- JDBC: Connection With MySQL Database
More on JDBC
Follow below links to learn more on JDBC and solving JDBC related issues :
You must log in to post a comment.