Connection Interface In Java
Connection Interface
In JDBC, a connection is the session between Java Application and database. The connection interface is a factory of Statement, DatabaseMetaData and PreparedStatement i.e. an object of connection can be used to get the object of Statement and DatabaseMetaData. It provides several methods for transaction management like commit(), rollback() etc. By default, the connection commits the changes after executing the queries.
Methods of Connection interface
public Statement createStatement()
This method is used to create a statement object, which can be used to execute SQL queries.
public Statement createStatement(int resultSetType,int resultSetConcurrency)
This method is used to create a statement object, which will generate ResultSet objects with the given type and concurrency.
public void setAutoCommit(boolean status)
This method is used to set the commit status. It is true by default.
public void commit()
This method is used to save the changes made since the previous commit/rollback permanent.
public void rollback()
This method is used to drop all the changes made, since the previous commit/rollback.
public void close()
This method is used to close the connection and releases JDBC resources immediately.
Summary
Thus, we learnt, JDBC connection is the session between Java Application and the database. The connection interface is a factory of Statement, DatabaseMetaData and PreparedStatement i.e. an object of connection can be used to get the object of Statement, DatabaseMetaData and also learn its important methods in Java.