java tutorial - JDBC Connection in java - java programming - learn java - java basics - java for beginners



Connection Interface in JDBC

  • Connection is nothing but a session among java application and database.
  • The Connection interface is a factory of Statement, PreparedStatement, and furthermore a DatabaseMetaData i.e. object of Connection can be used to get the object of Statement as well as DatabaseMetaData.
  • The Connection interface provide many methods for transaction management like commit(),rollback() etc.

Method of Connection Interface

MethodDescription
public Statement createStatement()It creates a statement object that can be used to execute SQL queries.
public Statement createStatement
(int resultSetType,int resultSetConcurrency)
It creates a Statement object that will generate ResultSet objects with the given type and concurrency.
public void setAutoCommit(boolean status)It is used to set the commit status. By default it is true.
public void commit()It saves the changes made since the previous commit/rollback permanent.
public void rollback() It drops all changes made since the previous commit/rollback.
public void close():It closes the connection and Releases JDBC resources immediately.

java.sql.Connection interface

  • Derby Connection object is not the garbage-collected up to every other JDBC (Java Database Connectivity) objects created as of which the connections is explicitly closed or else are themselves garbage-collected.
  • Once the connection is closed, no further JDBC requests can be made against objects created from the connection. Do not explicitly close the Connection object until no longer require it for executing statements.
  • A session-severity or higher exception causes the connection to close and all other JDBC objects against it to be closed.
  • System-severity exceptions may cause Derby system to shut down, which isn’t just shuts the connection however which implies no new connections must be created in the present Java Virtual Machine (JVM).

Related Searches to Jdbc Connection Interface