Package migratedb.v1.core.internal.jdbc
Class JdbcUtils
- java.lang.Object
-
- migratedb.v1.core.internal.jdbc.JdbcUtils
-
public final class JdbcUtils extends Object
Utility class for dealing with jdbc connections.
-
-
Constructor Summary
Constructors Constructor Description JdbcUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseConnection(@Nullable Connection connection)Quietly closes this connection.static voidcloseResultSet(ResultSet resultSet)Quietly closes this resultSet.static voidcloseStatement(Statement statement)Quietly closes this statement.static DatabaseMetaDatagetDatabaseMetaData(Connection connection)static StringgetDatabaseProductName(DatabaseMetaData databaseMetaData)static StringgetDatabaseProductVersion(DatabaseMetaData databaseMetaData)static ConnectionopenConnection(ConnectionProvider dataSource, int connectRetries, int connectRetriesInterval, DatabaseTypeRegister databaseTypeRegister)Opens a new connection fromdataSource.
-
-
-
Method Detail
-
openConnection
public static Connection openConnection(ConnectionProvider dataSource, int connectRetries, int connectRetriesInterval, DatabaseTypeRegister databaseTypeRegister) throws MigrateDbException
Opens a new connection fromdataSource.- Parameters:
dataSource- The data source to obtain the connection from.connectRetries- The maximum number of retries when attempting to connect to the database.connectRetriesInterval- The maximum time between retries in seconds- Returns:
- The new connection.
- Throws:
MigrateDbException- if the connection could not be opened.
-
closeConnection
public static void closeConnection(@Nullable Connection connection)
Quietly closes this connection. This method never throws an exception even if closing the connection fails.
-
closeStatement
public static void closeStatement(Statement statement)
Quietly closes this statement. This method never throws an exception even if closing the statement fails.
-
closeResultSet
public static void closeResultSet(ResultSet resultSet)
Quietly closes this resultSet. This method never throws an exception even if closing the result set fails.
-
getDatabaseMetaData
public static DatabaseMetaData getDatabaseMetaData(Connection connection)
-
getDatabaseProductName
public static String getDatabaseProductName(DatabaseMetaData databaseMetaData)
- Returns:
- The name of the database product. Example: Oracle, MySQL, ...
-
getDatabaseProductVersion
public static String getDatabaseProductVersion(DatabaseMetaData databaseMetaData)
- Returns:
- The version of the database product. Example: MariaDB 10.3, ...
-
-