From f11b3c7ec33d79a7f7978822033b2b76cf304bc6 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Wed, 14 Aug 2024 17:20:41 +0200 Subject: [PATCH] Upgraded class instanciate method. --- .../statoolinfos/util/sql/SQLUtils.java | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/fr/devinsy/statoolinfos/util/sql/SQLUtils.java b/src/fr/devinsy/statoolinfos/util/sql/SQLUtils.java index 10ada04..6ce15bf 100644 --- a/src/fr/devinsy/statoolinfos/util/sql/SQLUtils.java +++ b/src/fr/devinsy/statoolinfos/util/sql/SQLUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Christian Pierre MOMON + * Copyright (C) 2020-2024 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -18,6 +18,7 @@ */ package fr.devinsy.statoolinfos.util.sql; +import java.lang.reflect.InvocationTargetException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -192,23 +193,12 @@ public final class SQLUtils } else { - Class.forName("com.mysql.jdbc.Driver").newInstance(); + Class.forName("com.mysql.jdbc.Driver").getConstructor().newInstance(); result = DriverManager.getConnection(serverUrl + databaseName + "?useUnicode=true&characterEncoding=utf8", login, password); } } - catch (SQLException exception) - { - throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception); - } - catch (InstantiationException exception) - { - throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception); - } - catch (IllegalAccessException exception) - { - throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception); - } - catch (ClassNotFoundException exception) + catch (SQLException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException + | ClassNotFoundException exception) { throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception); }