Files
Toolbox/Database/src/main/java/fr/altarik/toolbox/database/AbstractSqlConnection.java
Quentin Legot 204198f143
All checks were successful
Test and Deploy / build (17, ubuntu-latest) (push) Successful in 3m55s
Test and Deploy / build (17, ubuntu-latest) (pull_request) Successful in 4m7s
Test and Deploy / deploy (17, ubuntu-latest) (push) Has been skipped
Test and Deploy / deploy (17, ubuntu-latest) (pull_request) Has been skipped
Remove deprecated method and remove redundant cast or throws declaration
2024-02-12 20:40:44 +01:00

36 lines
895 B
Java

package fr.altarik.toolbox.database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public abstract class AbstractSqlConnection implements SqlConnection {
protected final ConnectionConfig config;
protected Connection connection;
protected AbstractSqlConnection(ConnectionConfig config) throws SQLException {
this.config = config;
DriverManager.setLoginTimeout(3);
connect();
}
public void checkConnection() throws SQLException {
if(connection == null || connection.isClosed() || !connection.isValid(1))
connect();
}
@Override
public Connection getConnection() {
return connection;
}
@Override
public void close() throws Exception {
if(!connection.isClosed()) {
connection.close();
connection = null;
}
}
}