mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-03 18:43:43 +01:00 
			
		
		
		
	Close statements correctly, add update function
This commit is contained in:
		@@ -243,6 +243,7 @@ public class Database {
 | 
			
		||||
            try {
 | 
			
		||||
                statement = connection.prepareStatement(sql);
 | 
			
		||||
                statement.executeUpdate();
 | 
			
		||||
                statement.close();
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            catch (SQLException ex) {
 | 
			
		||||
@@ -263,6 +264,39 @@ public class Database {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the number of rows affected by either a DELETE or UPDATE query
 | 
			
		||||
     *
 | 
			
		||||
     * @param sql SQL query to execute
 | 
			
		||||
     * @return the number of rows affected
 | 
			
		||||
     */
 | 
			
		||||
    public int update(String sql) {
 | 
			
		||||
        int ret = 0;
 | 
			
		||||
        if (checkConnected()) {
 | 
			
		||||
            PreparedStatement statement = null;
 | 
			
		||||
            try {
 | 
			
		||||
                statement = connection.prepareStatement(sql);
 | 
			
		||||
                ret = statement.executeUpdate();
 | 
			
		||||
                statement.close();
 | 
			
		||||
                return ret;
 | 
			
		||||
            } catch (SQLException ex) {
 | 
			
		||||
                printErrors(ex);
 | 
			
		||||
                return 0;
 | 
			
		||||
            } finally {
 | 
			
		||||
                if (statement != null) {
 | 
			
		||||
                    try {
 | 
			
		||||
                        statement.close();
 | 
			
		||||
                    } catch (SQLException e) {
 | 
			
		||||
                        printErrors(e);
 | 
			
		||||
                        return 0;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the Integer. Only return first row / first field.
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user