diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java index c96bbf437..183a47e64 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/AndroidDAOFactory.java @@ -83,16 +83,15 @@ public class AndroidDAOFactory extends AbstractMobileDeviceManagementDAOFactory } } catch (SQLException e) { throw new MobileDeviceManagementDAOException("Error occurred while committing the transaction", e); - } finally { - closeConnection(); } } public static void closeConnection() throws MobileDeviceManagementDAOException { - - Connection con = currentConnection.get(); + Connection conn = currentConnection.get(); try { - con.close(); + if (conn != null) { + conn.close(); + } } catch (SQLException e) { log.error("Error occurred while close the connection"); } @@ -112,8 +111,6 @@ public class AndroidDAOFactory extends AbstractMobileDeviceManagementDAOFactory } } catch (SQLException e) { throw new MobileDeviceManagementDAOException("Error occurred while rollback the transaction", e); - } finally { - closeConnection(); } }