Example usage for org.json.simple JSONObject JSONObject

List of usage examples for org.json.simple JSONObject JSONObject

Introduction

In this page you can find the example usage for org.json.simple JSONObject JSONObject.

Prototype

JSONObject

Source Link

Usage

From source file:com.aerothai.database.servicetype.ServicetypeService.java

public JSONObject GetServicetypeAll(String opt) throws Exception {

    Connection dbConn = null;//from   www.  java2s  .  co m
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "list");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM service_type";

        if (isNotNull(opt))
            query = "SELECT * FROM service_type WHERE" + opt;

        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idservice_type"));
            jsonData.put("details", rs.getString("details"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;

        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}

From source file:com.aerothai.database.servicemethod.ServicemethodService.java

public JSONObject GetServicemethodAll(String opt) throws Exception {

    Connection dbConn = null;//from w w w.j  ava 2s.c  om
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "list");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM service_method";

        if (isNotNull(opt))
            query = "SELECT * FROM service_method WHERE" + opt;

        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idservice_method"));
            jsonData.put("details", rs.getString("details"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;

        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}

From source file:com.itmanwuiso.checksums.dao.Formatter.java

@SuppressWarnings("unchecked")
public JSONObject resultToJson(HashResult result) {
    JSONObject back = new JSONObject();
    if (null == result) {
        return back;
    }/*from   w  ww  .  j  ava  2s .com*/

    back.put("filePath", result.getFilePath());
    back.put("fileSize", new Long(result.getFileSize()));

    JSONObject hashes = new JSONObject();

    if (null != result.getHashes() && !result.getHashes().isEmpty()) {
        for (Entry<String, byte[]> e : result.getHashes().entrySet()) {
            hashes.put(e.getKey(), bytesToString(e.getValue()));
        }
    }

    back.put("hashes", hashes);

    return back;
}

From source file:geo.model.MRTStation.java

public JSONObject getJSONObject() {
    JSONObject obj = new JSONObject();
    try {//  w  ww . j av a  2 s .c o m
        obj.put("code", code);
        obj.put("stationName", stationName);
        obj.put("workingName", workingName);
        obj.put("lineCode", lineCode);
        obj.put("stationNumber", stationNumber);
        obj.put("lat", lat);
        obj.put("lng", lng);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return obj;
}

From source file:com.aerothai.database.model.ModelService.java

public JSONObject GetModelAll(int idunit, String opt) throws Exception {

    Connection dbConn = null;/*ww w .  j  a v a2 s .  c  om*/
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "list");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM model";
        if (idunit > 0) {
            query = query + " WHERE idunit =" + idunit;
            if (isNotNull(opt))
                query = query + " AND " + opt;
        } else {
            if (isNotNull(opt))
                query = "SELECT * FROM model WHERE" + opt;
        }

        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idmodel"));
            jsonData.put("details", rs.getString("details"));
            jsonData.put("idunit", rs.getString("idunit"));
            jsonData.put("iddevice_type", rs.getString("iddevice_type"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;

        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}

From source file:com.aerothai.database.unit.UnitService.java

public JSONObject GetUnitAll(String action, String opt) throws Exception {

    Connection dbConn = null;//www .j  av a2s  . c o m
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "list");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM unit";
        if (!action.equals("0")) {
            query = query + " WHERE action =" + action;
            if (isNotNull(opt))
                query = query + " AND " + opt;
        } else {
            if (isNotNull(opt))
                query = "SELECT * FROM unit WHERE" + opt;
        }

        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idunit"));
            jsonData.put("name", rs.getString("name"));
            jsonData.put("shortname", rs.getString("shortname"));
            jsonData.put("action", rs.getString("action"));
            jsonData.put("addjob", rs.getString("addjob"));
            jsonData.put("filename", rs.getString("filename"));
            jsonData.put("menu", rs.getString("menu"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;

        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}

From source file:com.aerothai.database.accessory.AccessoryService.java

public JSONObject GetAccessoryAll(int idunit, String opt) throws Exception {

    Connection dbConn = null;//from ww w.j ava2 s.co  m
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "list");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM accessory";
        if (idunit > 0) {
            query = query + " WHERE idunit =" + idunit;
            if (isNotNull(opt))
                query = query + " AND " + opt;
        } else {
            if (isNotNull(opt))
                query = "SELECT * FROM accessory WHERE" + opt;
        }

        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idaccessory"));
            jsonData.put("details", rs.getString("details"));
            jsonData.put("idunit", rs.getString("idunit"));
            jsonData.put("iddevice_type", rs.getString("iddevice_type"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;

        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}

From source file:com.aerothai.database.radiosignal.RadiosignalService.java

public JSONObject GetRadiosignalAll(String opt) throws Exception {

    Connection dbConn = null;/*ww w  . ja  v a 2  s  . co  m*/
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "list");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM radio_signal";

        if (isNotNull(opt))
            query = "SELECT * FROM radio_signal WHERE" + opt;

        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idsignal"));
            jsonData.put("idjob", rs.getString("idjob"));
            jsonData.put("asset_no", rs.getString("asset_no"));
            jsonData.put("freq", rs.getString("freq"));
            jsonData.put("rms", rs.getString("rms"));
            jsonData.put("peak", rs.getString("peak"));
            jsonData.put("resid", rs.getString("resid"));
            jsonData.put("time_err", rs.getString("time_err"));
            jsonData.put("power_at_15", rs.getString("power_at_15"));
            jsonData.put("power_at_30", rs.getString("power_at_30"));
            jsonData.put("rec_level", rs.getString("rec_level"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;

        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}

From source file:com.aerothai.database.sparepart.SparepartService.java

public JSONObject GetSparepartAll(int idunit, String opt) throws Exception {

    Connection dbConn = null;//  w ww .ja  v  a  2s  .co m
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "list");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM spare_part";
        if (idunit > 0) {
            query = query + " WHERE idunit =" + idunit;
            if (isNotNull(opt))
                query = query + " AND " + opt;
        } else {
            if (isNotNull(opt))
                query = "SELECT * FROM spare_part WHERE" + opt;
        }

        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idspare"));
            jsonData.put("details", rs.getString("details"));
            jsonData.put("amount", rs.getString("amount"));
            jsonData.put("price", rs.getString("price"));
            jsonData.put("date", rs.getString("date"));
            jsonData.put("idunit", rs.getString("idunit"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;

        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}

From source file:com.aerothai.database.jobevaluate.JobevaluateService.java

public JSONObject GetJobevaluateAll(int idjob, String opt) throws Exception {

    Connection dbConn = null;/*from w ww .  j  a v  a2  s . c  o m*/
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "list");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM job_evaluate";
        if (idjob > 0) {
            query = query + " WHERE idjob =" + idjob;
            if (isNotNull(opt))
                query = query + " AND " + opt;
        } else {
            if (isNotNull(opt))
                query = "SELECT * FROM job_evaluate WHERE" + opt;
        }

        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idjob_evaluate"));
            jsonData.put("idjob", rs.getString("idjob"));
            jsonData.put("staff", rs.getString("staff"));
            jsonData.put("service", rs.getString("service"));
            jsonData.put("comment", rs.getString("comment"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;

        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}