All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.ugli.habanero.j.internal.CloseUtil Maven / Gradle / Ivy

There is a newer version: 1.8.1.1
Show newest version
package se.ugli.habanero.j.internal;

import java.io.Closeable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public final class CloseUtil {

	public static void close(final Object... objects) {
		for (final Object obj : objects)
			if (obj != null)
				try {
					if (obj instanceof Connection)
						((Connection) obj).close();
					else if (obj instanceof Statement)
						((Statement) obj).close();
					else if (obj instanceof ResultSet)
						((ResultSet) obj).close();
					// Java 7
					// else if (obj instanceof AutoCloseable)
					// ((AutoCloseable) obj).close();
					else if (obj instanceof Closeable)
						((Closeable) obj).close();
					else
						obj.getClass().getMethod("close").invoke(obj);
				} catch (final Exception e) {
					e.printStackTrace();
				}
	}

	private CloseUtil() {

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy