Java Source Code: __.te.TestSupportsTransactions


   1: import java.sql.Connection;
   2: import java.sql.SQLException;
   3: import java.sql.DatabaseMetaData;
   4: 
   5: import jcb.util.DatabaseUtil;
   6: import jcb.db.VeryBasicConnectionManager;
   7: 
   8: /**
   9:  *
  10:  * @author Mahmoud Parsian
  11:  * @email  admin@jdbccookbook.com
  12:  *
  13:  */
  14:	   public class TestSupportsTransactions {
  15:
  16:    public static boolean supportsTransactions(Connection conn)
  17:	          throws SQLException {
  18:
  19:	          if (conn == null) {
  20:            return false;
  21:        }
  22:
  23:        DatabaseMetaData dbMetaData = conn.getMetaData();
  24:	          if (dbMetaData == null) {
  25:            // metadata is not supported
  26:            return false;
  27:        }
  28:
  29:        return dbMetaData.supportsTransactions();
  30:    }
  31:
  32:	      public static void main(String[] args) {
  33:        Connection conn = null;
  34:	          try {
  35:            String dbVendor = args[0];
  36:            conn = VeryBasicConnectionManager.getConnection(dbVendor);
  37:            System.out.println("--- begin Test ---");
  38:            System.out.println("dbVendor="+dbVendor);
  39:            System.out.println("conn="+conn);
  40:            System.out.println("Transaction Support:"+
  41:               supportsTransactions(conn));
  42:            System.out.println("--- end of Test ---");
  43:       }
  44:	      catch(Exception e){
  45:        e.printStackTrace();
  46:        System.exit(1);
  47:    }
  48:	      finally {
  49:        DatabaseUtil.close(conn);
  50:        }
  51:    }
  52:}