Test Supports Transactions : Transaction « Database SQL JDBC « Java






Test Supports Transactions

 
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class TestSupportsTransactions {

  public static boolean supportsTransactions(Connection conn) throws SQLException {

    if (conn == null) {
      return false;
    }

    DatabaseMetaData dbMetaData = conn.getMetaData();
    if (dbMetaData == null) {
      // metadata is not supported
      return false;
    }

    return dbMetaData.supportsTransactions();
  }
  public static Connection getOracleConnection() throws Exception {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:scorpian";
    String username = "userName";
    String password = "pass";
    Class.forName(driver); // load Oracle driver
    Connection conn = DriverManager.getConnection(url, username, password);
    return conn;
  }
  public static void main(String[] args)throws Exception {
    Connection conn = getOracleConnection();
    try {
      System.out.println("conn=" + conn);
      System.out.println("Transaction Support:" + supportsTransactions(conn));
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    } finally {
      try {
        conn.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }
}
           
         
  








Related examples in the same category

1.Demo MySql Transaction
2.Transaction Pairs
3.Transaction Info
4.JDBC Transaction
5.Transaction Pairs 2
6.Using a database transaction with JDBC