Connection: close() : Connection « java.sql « Java by API






Connection: close()

  
/* 
 * */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
  public static void main(String[] args) throws Exception {
    if (conn != null) {
      System.out.println("Connection attempt was successful!");

      try {
        conn.close();
      } catch (SQLException ex) {
        ex.printStackTrace();
        System.out.println("Problem closing the connection");
      }
    }
  }

  static Connection conn;

  static Statement st;

  static {
    try {
      // Step 1: Load the JDBC driver.
      Class.forName("org.hsqldb.jdbcDriver");
      System.out.println("Driver Loaded.");
      // Step 2: Establish the connection to the database.
      String url = "jdbc:hsqldb:data/tutorial";

      conn = DriverManager.getConnection(url, "sa", "");
      System.out.println("Got Connection.");

      st = conn.createStatement();
    } catch (Exception e) {
      System.err.println("Got an exception! ");
      e.printStackTrace();
      System.exit(0);
    }
  }
}

           
         
    
  








Related examples in the same category

1.Connection.TRANSACTION_NONE
2.Connection.TRANSACTION_READ_COMMITTED
3.Connection.TRANSACTION_READ_UNCOMMITTED
4.Connection.TRANSACTION_REPEATABLE_READ
5.Connection.TRANSACTION_SERIALIZABLE
6.Connection: commit()
7.Connection: createStatement()
8.Connection: createStatement(int resultSetType, int resultSetConcurrency)
9.Connection: getAutoCommit()
10.Connection: getCatalog()
11.Connection: getMetaData()
12.Connection: getTransactionIsolation()
13.Connection: getWarnings()
14.Connection: nativeSQL(String sql)
15.Connection: prepareCall(String sql)
16.Connection: prepareStatement(String sql)
17.Connection: rollback()
18.Connection: rollback(Savepoint savepoint)
19.Connection: setAutoCommit(boolean autoCommit)
20.Connection: setSavepoint(String name)
21.Connection: setTransactionIsolation(int level)