SHOW:
|
|
- or go back to the newest paste.
| 1 | public final boolean hasAcccount(final UUID uuid) {
| |
| 2 | checkConnectAndReconnectIfWant(); | |
| 3 | try {
| |
| 4 | final PreparedStatement ps = this.connection | |
| 5 | .prepareStatement("SELECT Uuid FROM `EVENT__players` WHERE Uuid = ?");
| |
| 6 | ps.setString(1, uuid.toString()); | |
| 7 | final ResultSet result = ps.executeQuery(); | |
| 8 | final boolean hasAccount = result.next(); | |
| 9 | ps.close(); | |
| 10 | return hasAccount; | |
| 11 | } catch (final SQLException e) {
| |
| 12 | System.out.println("Erreur lors de la tentative de verification de l'existance du compte dans la bdd : "
| |
| 13 | + e.getMessage()); | |
| 14 | e.printStackTrace(); | |
| 15 | return false; | |
| 16 | } | |
| 17 | } | |
| 18 | ||
| 19 | ||
| 20 | private final void checkConnectAndReconnectIfWant() {
| |
| 21 | if (!isConnect()) | |
| 22 | connect(); | |
| 23 | } | |
| 24 | ||
| 25 | private final void connect() {
| |
| 26 | try {
| |
| 27 | this.connection = DriverManager.getConnection( | |
| 28 | "jdbc:mysql://" + this.host + "/" + this.bddName + "?autoReconnect=true", this.userName, | |
| 29 | this.password); | |
| 30 | } catch (final SQLException e) {
| |
| 31 | System.out.println("Erreur lors de la tentative de connection à la bdd: " + e.getMessage());
| |
| 32 | } | |
| 33 | } | |
| 34 | ||
| 35 | - | public final void disconnect() {
|
| 35 | + | private final boolean isConnect() {
|
| 36 | - | if (isConnect()) |
| 36 | + | |
| 37 | - | try {
|
| 37 | + | return this.connection != null && !this.connection.isClosed(); |
| 38 | - | this.connection.close(); |
| 38 | + | } catch (SQLException e) {
|
| 39 | - | } catch (final SQLException e) {
|
| 39 | + | |
| 40 | - | System.out.println("Erreur lors de la tentative de deconnection a la bdd : " + e.getMessage());
|
| 40 | + | |
| 41 | - | } |
| 41 | + | |
| 42 | } |