package org.nhooo.example.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.DatabaseMetaData; import java.sql.SQLException; public class TransactionSupportChecker { private static final String URL = "jdbc:mysql://localhost/nhooo"; private static final String USERNAME = "root"; private static final String PASSWORD = ""; public static void main(String[] args) { try (Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD)) { DatabaseMetaData metadata = connection.getMetaData(); boolean supported = metadata.supportsTransactions(); System.out.println("Supports Transaction = " + supported); } catch (SQLException e) { e.printStackTrace(); } } }
Maven依赖
<!-- https://search.maven.org/remotecontent?filepath=mysql/mysql-connector-java/8.0.17/mysql-connector-java-8.0.17.jar --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.17</version> </dependency>