public class TestMySQL { public static void main(String[] args) { String path = Thread.currentThread().getContextClassLoader ().getResource("").toString(); System.out.println("==========currentThread:"+path); TestMySQL tm = new TestMySQL(); System.out.println("==========File:"+tm.getClass().getResource("").getFile()); System.out.println("==========Path:"+tm.getClass().getResource("").getPath()); String jdbcPath = tm.getClass().getResource("").getPath(); try { File pFile = new File(jdbcPath+"jdbc.properties"); FileInputStream pInStream=null; try { pInStream = new FileInputStream(pFile ); } catch (FileNotFoundException e) { e.printStackTrace(); } Properties pInfo = new Properties(); try { pInfo.load(pInStream ); } catch (IOException e) { e.printStackTrace(); } String drive = pInfo.getProperty("driver"); String url = pInfo.getProperty("url"); String user = pInfo.getProperty("user"); String pwd = pInfo.getProperty("pwd"); Class.forName(drive); Connection conn = DriverManager.getConnection(url, user, pwd); DatabaseMetaData metaData = conn.getMetaData(); // 是否支持的事务 boolean isSupport = metaData.supportsTransactions(); System.out.println("======isSupportsTransactions:"+isSupport); // 是否支持的Connection.TRANSACTION_SERIALIZABLE等级事务 boolean isSupportLevel = metaData .supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE); System.out.println("======isSupportLevel:"+isSupportLevel); // 获取默认事务 int defaultIsolation = metaData.getDefaultTransactionIsolation(); System.out.println("======DefaultTransactionIsolation:"+defaultIsolation); if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } }
/** 不支持事务 * A constant indicating that transactions are not supported. */ int TRANSACTION_NONE = 0; /**支持事务,脏数据,不重读,幻读可能发生。 * A constant indicating that * dirty reads, non-repeatable reads and phantom reads can occur. * This level allows a row changed by one transaction to be read * by another transaction before any changes in that row have been * committed (a "dirty read"). If any of the changes are rolled back, * the second transaction will have retrieved an invalid row. */ int TRANSACTION_READ_UNCOMMITTED = 1; /**支持事务,不重读,幻读可能发生。 * A constant indicating that * dirty reads are prevented; non-repeatable reads and phantom * reads can occur. This level only prohibits a transaction * from reading a row with uncommitted changes in it. */ int TRANSACTION_READ_COMMITTED = 2; /**支持事务,幻读可能发生。 * A constant indicating that * dirty reads and non-repeatable reads are prevented; phantom * reads can occur. This level prohibits a transaction from * reading a row with uncommitted changes in it, and it also * prohibits the situation where one transaction reads a row, * a second transaction alters the row, and the first transaction * rereads the row, getting different values the second time * (a "non-repeatable read"). */ int TRANSACTION_REPEATABLE_READ = 4; /**支持事务,脏数据,不重读,幻读不可能发生。 * A constant indicating that * dirty reads, non-repeatable reads and phantom reads are prevented. * This level includes the prohibitions in * <code>TRANSACTION_REPEATABLE_READ</code> and further prohibits the * situation where one transaction reads all rows that satisfy * a <code>WHERE</code> condition, a second transaction inserts a row that * satisfies that <code>WHERE</code> condition, and the first transaction * rereads for the same condition, retrieving the additional * "phantom" row in the second read. */ int TRANSACTION_SERIALIZABLE = 8;
冰雪魔女 2021-02-05
荡神戏魔 2018-04-04
伍仔 2016-12-21
早安 2020-07-23
吟风 2017-04-23
藏家011 2022-10-31
牵马的蜘蛛 2016-03-29
寒江独钓 2017-05-21
吟风 2017-01-18
沙落雁 2016-11-21
道友请留步 2025-03-26
道友请留步 2025-03-26
藏家708 2025-03-26
leoaim 2025-03-25
恭明惠 2025-03-26
藏家468 2025-03-26
藏家101 2025-03-25
藏家101 2025-03-25
藏家101 2025-03-25
藏家068 2025-03-25