A Connection enables the session between java application and database. The Connection interface has 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, any changes after executing query is commits connection automatically.
Useful methods in
java.sql.Connection interface:
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 is used to drop all changes made since the previous commit/rollback. |
public void close() | It is used close the connection and Releases a JDBC resources immediately. |
SOURCE:TestDBConnection.java
OUTPUT
Connected Data base successfully ..!
0 comments :
Post a Comment