IoT CAS Frameworks/IOT_Server/Device_Management_Framework/Device_Management_API/DeviceManagment/src/com/adminAPI/DeviceManagment.java
public boolean  updateResourceConfig(Connection connection,String updateJson) {
        String customername = null;
        String service = null;
        String resourceid = null;
        String name = null;
        String value = null;
        int res = 0;
        String szSerQuery;
        String szResQuery;
        try {
            if (connection != null) {
                
                st = connection.createStatement();
                
                try {
                    JSONParser parser = new JSONParser();
                    
                    System.out.println("parser=" + parser.toString());
                    
                    System.out.println("updateJson=" + updateJson);
                    
                    JSONObject jsonObject = (JSONObject) parser.parse(updateJson);
                    
                    JSONObject jsonObj = (JSONObject) jsonObject.get("resourceconfig");
                    
                    System.out.println("jsonObj=" + jsonObj.toString());
                    
                    customername = (String) jsonObj.get("customer");
                    
                    System.out.println("customer=" + customername);
                    
                    service = (String) jsonObj.get("service");
                    
                    if (service != null) {
                        
                        if (service.equalsIgnoreCase("null") || service.equals("")) {
                            
                            szSerQuery = "service='null'";
                            
                        } else {
                            
                            szSerQuery = "service = '" + service + "'";
                        }
                        
                    } else {
                        
                        szSerQuery = "service='null'";
                        
                    }
                    
                    System.out.println("service=" + service);
                    
                    resourceid = (String) jsonObj.get("resourceid");
                    
                    if (resourceid != null) {
                        
                        if (resourceid.equalsIgnoreCase("null") || resourceid.equals("")) {
                            
                            szResQuery = "resourceid='null'";
                            
                        } else {
                            
                            szResQuery = "resourceid = '" + resourceid + "'";
                        }
                        
                    } else {
                        
                        szResQuery = "resourceid='null'";
                        
                    }
                    
                    System.out.println("resourceid=" + resourceid);
                    
                    JSONArray params = (JSONArray) jsonObj.get("params");
                    
                    Iterator itr = params.iterator();
                    
                    while (itr.hasNext()) {
                        
                        JSONObject jsObj = (JSONObject) itr.next();
                        
                        name = (String) jsObj.get("ParamName");
                        
                        value = (String) jsObj.get("ParamValue");
                        
                        String szUpdateQuery = "update resourceconfig set paramvalue='" + value + "' where "
                                + "customerid=(select id from customerinfo where customername='" + customername
                                + "') and " + szSerQuery + " and " + szResQuery + " and paramname='" + name + "'";
                        
                        System.out.println("UpdateResourceConfig Query ==>" + szUpdateQuery);
                        
                        res = st.executeUpdate(szUpdateQuery);
                        
                    }
                    if (res != 0) {
                        
                        return true;
                        
                    } else {
                        
                        System.err.println("Error while doing updation operation");
                        return false;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("Error while parsing the json");
                   
                }
            } else {
                System.out.println("Connection is null");
               
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("Error while connecting with the database"+e);
            
        } finally {
            try {
                if (connection != null) {
                    connection.close();
                }
                if (st != null) {
                    st.close();
                }
                if (customername != null) {
                    customername = null;
                }
                if (service != null) {
                    service = null;
                }
                if (resourceid != null) {
                    resourceid = null;
                }
                if (name != null) {
                    name = null;
                }
                if (value != null) {
                    value = null;
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
                System.err.println("Error while closing connection "+ ex);
            }
        }
         return false;
    }
/**
 * This Method is Used to Updated Resource
 * @param connection
 * @param updateJson
 * @return updatedResourceConfiguration Data
 */
This Method is Used to Updated Resource
@param connection
@param updateJson
@return updatedResourceConfiguration Data
This Method is Used to Updated Resource @param connection @param updateJson @return updatedResourceConfiguration Data
public boolean  updateResourceConfig(Connection connection,String updateJson) {
        String customername = null;
        String service = null;
        String resourceid = null;
        String name = null;
        String value = null;
        int res = 0;
        String szSerQuery;
        String szResQuery;
        try {
            if (connection != null) {
                st = connection.createStatement();
                try {
                    JSONParser parser = new JSONParser();
                    System.out.println("parser=" + parser.toString());
                    System.out.println("updateJson=" + updateJson);
                    JSONObject jsonObject = (JSONObject) parser.parse(updateJson);
                    JSONObject jsonObj = (JSONObject) jsonObject.get("resourceconfig");
                    System.out.println("jsonObj=" + jsonObj.toString());
                    customername = (String) jsonObj.get("customer");
                    System.out.println("customer=" + customername);
                    service = (String) jsonObj.get("service");
                    if (service != null) {
                        if (service.equalsIgnoreCase("null") || service.equals("")) {
                            szSerQuery = "service='null'";
                        } else {
                            szSerQuery = "service = '" + service + "'";
                        }
                    } else {
                        szSerQuery = "service='null'";
                    }
                    System.out.println("service=" + service);
                    resourceid = (String) jsonObj.get("resourceid");
                    if (resourceid != null) {
                        if (resourceid.equalsIgnoreCase("null") || resourceid.equals("")) {
                            szResQuery = "resourceid='null'";
                        } else {
                            szResQuery = "resourceid = '" + resourceid + "'";
                        }
                    } else {
                        szResQuery = "resourceid='null'";
                    }
                    System.out.println("resourceid=" + resourceid);
                    JSONArray params = (JSONArray) jsonObj.get("params");
                    Iterator itr = params.iterator();
                    while (itr.hasNext()) {
                        JSONObject jsObj = (JSONObject) itr.next();
                        name = (String) jsObj.get("ParamName");
                        value = (String) jsObj.get("ParamValue");
                        String szUpdateQuery = "update resourceconfig set paramvalue='" + value + "' where "
                                + "customerid=(select id from customerinfo where customername='" + customername
                                + "') and " + szSerQuery + " and " + szResQuery + " and paramname='" + name + "'";
                        System.out.println("UpdateResourceConfig Query ==>" + szUpdateQuery);
                        res = st.executeUpdate(szUpdateQuery);
                    }
                    if (res != 0) {
                        return true;
                    } else {
                        System.err.println("Error while doing updation operation");
                        return false;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("Error while parsing the json");
                }
            } else {
                System.out.println("Connection is null");
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("Error while connecting with the database"+e);
        } finally {
            try {
                if (connection != null) {
                    connection.close();
                }
                if (st != null) {
                    st.close();
                }
                if (customername != null) {
                    customername = null;
                }
                if (service != null) {
                    service = null;
                }
                if (resourceid != null) {
                    resourceid = null;
                }
                if (name != null) {
                    name = null;
                }
                if (value != null) {
                    value = null;
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
                System.err.println("Error while closing connection "+ ex);
            }
        }
         return false;
    }
public boolean updateResourceConfig ( Connection connection , String updateJson ) { String customername = null ; String service = null ; String resourceid = null ; String name = null ; String value = null ; int res = 0 ; String szSerQuery ; String szResQuery ; try { if ( connection != null ) { st = connection . createStatement ( ) ; try { JSONParser parser = new JSONParser ( ) ; System . out . println ( "parser=" + parser . toString ( ) ) ; System . out . println ( "updateJson=" + updateJson ) ; JSONObject jsonObject = ( JSONObject ) parser . parse ( updateJson ) ; JSONObject jsonObj = ( JSONObject ) jsonObject . get ( "resourceconfig" ) ; System . out . println ( "jsonObj=" + jsonObj . toString ( ) ) ; customername = ( String ) jsonObj . get ( "customer" ) ; System . out . println ( "customer=" + customername ) ; service = ( String ) jsonObj . get ( "service" ) ; if ( service != null ) { if ( service . equalsIgnoreCase ( "null" ) || service . equals ( "" ) ) { szSerQuery = "service='null'" ; } else { szSerQuery = "service = '" + service + "'" ; } } else { szSerQuery = "service='null'" ; } System . out . println ( "service=" + service ) ; resourceid = ( String ) jsonObj . get ( "resourceid" ) ; if ( resourceid != null ) { if ( resourceid . equalsIgnoreCase ( "null" ) || resourceid . equals ( "" ) ) { szResQuery = "resourceid='null'" ; } else { szResQuery = "resourceid = '" + resourceid + "'" ; } } else { szResQuery = "resourceid='null'" ; } System . out . println ( "resourceid=" + resourceid ) ; JSONArray params = ( JSONArray ) jsonObj . get ( "params" ) ; Iterator itr = params . iterator ( ) ; while ( itr . hasNext ( ) ) { JSONObject jsObj = ( JSONObject ) itr . next ( ) ; name = ( String ) jsObj . get ( "ParamName" ) ; value = ( String ) jsObj . get ( "ParamValue" ) ; String szUpdateQuery = "update resourceconfig set paramvalue='" + value + "' where " + "customerid=(select id from customerinfo where customername='" + customername + "') and " + szSerQuery + " and " + szResQuery + " and paramname='" + name + "'" ; System . out . println ( "UpdateResourceConfig Query ==>" + szUpdateQuery ) ; res = st . executeUpdate ( szUpdateQuery ) ; } if ( res != 0 ) { return true ; } else { System . err . println ( "Error while doing updation operation" ) ; return false ; } } catch ( Exception e ) { e . printStackTrace ( ) ; System . out . println ( "Error while parsing the json" ) ; } } else { System . out . println ( "Connection is null" ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; System . err . println ( "Error while connecting with the database" + e ) ; } finally { try { if ( connection != null ) { connection . close ( ) ; } if ( st != null ) { st . close ( ) ; } if ( customername != null ) { customername = null ; } if ( service != null ) { service = null ; } if ( resourceid != null ) { resourceid = null ; } if ( name != null ) { name = null ; } if ( value != null ) { value = null ; } } catch ( NullPointerException npe ) { npe . printStackTrace ( ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; System . err . println ( "Error while closing connection " + ex ) ; } } return false ; }
This Method is Used to Updated Resource
 @param connection
 @param updateJson
 @return updatedResourceConfiguration Data
This Method is Used to Updated Resource @param connection @param updateJson @return updatedResourceConfiguration Data