Home Java Tutorial Connection interface

Connection interface

by Techarge
2 minutes read

A Connection is a session between a 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.

The Connection interface provide many methods for transaction management like commit(), rollback() etc.

By default, connection commits the changes after executing queries.

Commonly used methods of Connection interface:

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

This article is contributed by Akash Gain. If you like Techarge and would like to contribute, you can also write an article using https://techarge.in/start-blogging-with-us/ or mail your article to techarge.in@gmail.com . See your article appearing on the Techarge home page and help other to learn. 🙂

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.