Example usage for java.sql PreparedStatement setTimestamp

List of usage examples for java.sql PreparedStatement setTimestamp

Introduction

In this page you can find the example usage for java.sql PreparedStatement setTimestamp.

Prototype

void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given java.sql.Timestamp value.

Usage

From source file:com.pari.nm.utils.db.InventoryDBHelper.java

public static boolean updateDeviceDetails(NetworkNode device, boolean manage, String deviceKnownIp,
        boolean updatevirtualDevice, int updateDeviceId, boolean discoveryJob) {
    PreparedStatement ps = null;
    Connection c = null;/*from  w ww  .jav  a  2 s .c  o m*/
    int deviceId = updateDeviceId;
    try {
        c = DBHelper.getConnection();
        c.setAutoCommit(false);
        boolean insert = true;

        if (updatevirtualDevice) {
            insert = false;
            ps = c.prepareStatement(DBHelperConstants.NODE_UPDATE);
        } else {
            ps = c.prepareStatement(DBHelperConstants.NODE_INSERT);
        }
        Timestamp ts = null;
        // CSCtr59009 -Bug fix - Fix for timestamp issue of discovered
        // devices.
        if (device.getDiscoveredTime() > 0) {
            ts = new Timestamp(device.getDiscoveredTime());
        } else {
            synchronized (lock) {
                // Even though synchronization here looks unnecessary, all
                // we are trying to do
                // is to gaurantee a distinct timestamp value across
                // multiple threads in which
                // updateDeviceDetails() method is invoked
                ts = new Timestamp(System.currentTimeMillis());
                Thread.sleep(1);
            }
        }
        if (insert) {
            // logger.debug("Before inserting before device: " +
            // deviceKnownIp);
            ps.setString(1, deviceKnownIp);
            // ps.setInt(2, device.getVersion().getVersionType().typeInt);
            ps.setInt(2, device.getVersion().getOsTypeDetails().getOsId());
            // ps.setString(3, device.getVersion().getDeviceType());

            // Setting Device Family as family
            ps.setString(3, device.getVersion().getDeviceFamily());
            ps.setString(4, device.getVendorName());
            ps.setString(5, manage ? "m" : "u");

            ps.setTimestamp(6, ts);
            ps.setInt(7, device.getDeviceMode());
            ps.setString(8, device.getSysObjectID());
            // Setting ShowFamilyAs as Product_Family
            ps.setString(9, device.getVersion().getShowFamilyAs());
            ps.setString(10, device.getVersion().getOsTypeDetails().getOsAlias());
            ps.setString(11, device.getProductId());
        } else {
            // ps.setString(1, device.getVersion().getDeviceType());

            // Setting Device Family as family
            ps.setString(1, device.getVersion().getDeviceFamily());
            ps.setString(2, device.getVendorName());
            ps.setString(3, manage ? "m" : "u");
            // ps.setInt(4, device.getVersion().getVersionType().typeInt);
            ps.setInt(4, device.getVersion().getOsTypeDetails().getOsId());
            ps.setInt(5, device.getDeviceMode());
            ps.setTimestamp(6, ts); // CSCtr59009 - updating timestamp also
            if (device.getSysObjectID() != null && !device.getSysObjectID().isEmpty()) {
                ps.setString(7, device.getSysObjectID());
            } else {
                ps.setString(7, null);
            }
            // Setting ShowFamilyAs as Product_Family
            ps.setString(8, device.getVersion().getShowFamilyAs());
            ps.setString(9, device.getVersion().getOsTypeDetails().getOsAlias());
            ps.setString(10, device.getProductId());
            ps.setInt(11, deviceId);

        }
        int id = -1;
        if (insert) {
            synchronized (lock) {
                ps.executeUpdate();
                id = getCurrentMaxNodeId(c, device);
            }
        } else {
            ps.executeUpdate();
        }

        if (insert) {
            // logger.debug("Just inserted device: " + deviceKnownIp);
            if (id >= 0) {
                logger.debug("Setting nodeId: " + id + " for device: " + deviceKnownIp);
                device.setNodeId(id);
                /*
                 * DeviceWeightage weightage = DeviceWeightageManager.getInstance ().getWeightage(device);
                 * device.setWeightageObj(weightage);
                 */
                if (!discoveryJob) {
                    BackupSoftwareImageRequestProcessor.getInstance().processRequest(id);
                    // logger.debug("Device :"+id+" is added to Automatic Backup Job.... ");
                }
            } else {
                throw new Exception("Unable to get new device ID for device: " + deviceKnownIp);
            }
            /*
             * try {
             *
             * PreparedStatement ps1 = null; // rs = DBHelper.executeQueryNoCommit(c,
             * "select max(id) as id from nodes"); ps1 = c.prepareStatement(DBHelperConstants.NODE_DISOVERED);
             * ps1.setTimestamp(1, ts); rs = ps1.executeQuery();
             *
             * if ((rs != null) && rs.next()) { int id = rs.getInt("ID");
             *
             * device.setNodeId(id); } } catch (Exception ex) { ex.printStackTrace(); } finally { try { ps1.close();
             * } catch (Exception ex) {} }
             */
        } else {
            device.setNodeId(deviceId);
        }
        c.commit();
    } catch (Exception ee) {
        ee.printStackTrace();
        logger.warn("Error while updating deviceDetails for the deviceId " + updateDeviceId, ee);
        try {
            if (c != null) {
                c.rollback();
            }
        } catch (Exception e) {
        }
        return false;
    } finally {
        try {
            if (ps != null) {
                ps.close();
            }
        } catch (Exception ee) {
        }

        try {
            if (c != null) {
                c.setAutoCommit(true);
            }
        } catch (Exception e) {
        }

        try {
            DBHelper.releaseConnection(c);
        } catch (Exception ee) {
        }
    }
    return true;
}

From source file:com.pari.nm.utils.db.InventoryDBHelper.java

public static void insertDiscoveredDevice(DiscoveredDevice discDevice) {
    Connection c = null;/*from ww w. j a va 2s. c  o  m*/
    PreparedStatement ps = null;
    try {
        DBHelper.executeUpdate("delete from discovered_devices where ipaddress='" + discDevice.getIpAddress()
                + "' and customer_id=" + discDevice.getCustomer_id() + " and instance_id="
                + discDevice.getInstanceId());

        c = DBHelper.getConnection();
        ps = c.prepareStatement(DBHelperConstants.INSERT_DISCOVERED_DEVICE);
        ps.setInt(1, discDevice.getCustomer_id());
        ps.setInt(2, discDevice.getInstanceId());
        ps.setString(3, discDevice.getIpAddress());
        ps.setString(4, discDevice.getMacAddress());
        ps.setString(5, discDevice.getNodeName());
        ps.setString(6, discDevice.getDescription());
        ps.setString(7, discDevice.getDevice_family());
        ps.setString(8, discDevice.getProduct_family());
        ps.setString(9, discDevice.getProduct_model());
        ps.setString(10, discDevice.getOSName());
        ps.setString(11, discDevice.getOSVersion());
        ps.setString(12, discDevice.getVendor_name());
        if (discDevice.isManaged()) {
            ps.setString(13, "Yes");
        } else {
            // CSCtr61612 - Setting of 'isManaged' is based on if the
            // network
            // node is present in the same customer and instance
            VirtualDevice vd = new VirtualDevice();
            vd.setIpAddress(discDevice.getIpAddress());
            int[] nodes = NetworkNodeCache.getInstance().getMatchingNodeIds(vd, discDevice.getCustomer_id());
            if (nodes != null && nodes.length > 0) {
                ps.setString(13, "Yes");
            } else {
                ps.setString(13, "No");
            }
        }
        ps.setString(14, discDevice.getDiscovered_from());
        ps.setString(15, discDevice.getDiscovery_method());
        ps.setString(16, discDevice.getDiscovery_credential());
        ps.setString(17, null);
        ps.setTimestamp(18, discDevice.getDiscovery_time() == null ? (new Timestamp(System.currentTimeMillis()))
                : (new Timestamp(Long.parseLong(discDevice.getDiscovery_time()))));

        ps.executeUpdate();

        // customer_id, ipaddress, macaddress, hostname, device_family,
        // product_family, product_model, vendor_name,
        // discovered_from, discovery_method, discovery_credential,
        // current_state, discovery_time

    } catch (Exception ee) {
        ee.printStackTrace();
        logger.warn("Error while inserting into discovered devices", ee);
    } finally {
        try {
            ps.close();
        } catch (Exception ee) {
        }
        try {
            DBHelper.releaseConnection(c);
        } catch (Exception ee) {
        }
    }
}

From source file:com.pari.nm.utils.db.InventoryDBHelper.java

public static void insertModuleEolInfo(String modFilePath) {
    if (InventoryDBHelper.isModulesPopulated()) {
        return;// w ww.  j a  v a 2  s  .c o m
    }
    Connection c = null;
    PreparedStatement ps = null;
    InputStream in = null;
    try {
        if (modFilePath != null && (modFilePath.startsWith("/") || modFilePath.startsWith("\\"))) {
            modFilePath = modFilePath.substring(1);
        }
        in = Thread.currentThread().getContextClassLoader().getResourceAsStream(modFilePath);

        c = DBHelper.getConnection();
        c.setAutoCommit(false);
        ps = c.prepareStatement(DBHelperConstants.INSERT_MODULE_EOL_DB);

        StringBuffer sbuf = new StringBuffer();
        byte[] buf = new byte[8096];
        int read = -1;
        while ((read = in.read(buf)) != -1) {
            sbuf.append(new String(buf, 0, read));
        }

        StringTokenizer st = new StringTokenizer(sbuf.toString(), "\n");
        if (st.hasMoreElements()) {
            st.nextElement(); // takeout the header
        }
        while (st.hasMoreElements()) {
            String line = st.nextToken().trim();
            if (line.length() == 0) {
                continue;
            }
            StringTokenizer stt = new StringTokenizer(line, "\t");
            String fru = null;
            String deviceType = null;
            String url = null;
            Timestamp aDate = null;
            Timestamp eosDate = null;
            Timestamp eolDate = null;
            Timestamp eocrDate = null;
            Timestamp eoeDate = null;
            if (stt.hasMoreTokens()) {
                fru = stt.nextToken();
            }
            if (stt.hasMoreTokens()) {
                deviceType = stt.nextToken();
            }
            if (stt.hasMoreTokens()) {
                url = stt.nextToken();
            }
            if (stt.hasMoreTokens()) {
                aDate = getTimestamp(stt.nextToken());
            }
            if (stt.hasMoreTokens()) {
                eosDate = getTimestamp(stt.nextToken());
            }
            if (stt.hasMoreTokens()) {
                eolDate = getTimestamp(stt.nextToken());
            }
            if (stt.hasMoreTokens()) {
                eoeDate = getTimestamp(stt.nextToken());
            }
            if (stt.hasMoreTokens()) {
                eocrDate = getTimestamp(stt.nextToken());
            }

            ps.setString(1, fru);
            ps.setString(2, url);
            ps.setString(3, deviceType);
            ps.setTimestamp(4, aDate);
            ps.setTimestamp(5, eosDate);
            ps.setTimestamp(6, eolDate);
            ps.setTimestamp(7, eocrDate);
            ps.setTimestamp(8, eoeDate);
            ps.executeUpdate();
        }
    } catch (Exception ee) {
        logger.warn("Error in insertModuleEolInfo", ee);
    } finally {
        try {
            c.commit();

        } catch (Exception ee) {
        }
        try {
            c.setAutoCommit(true);

        } catch (Exception ee) {
        }

        try {
            ps.close();
        } catch (Exception ee) {
        }

        try {
            DBHelper.releaseConnection(c);
        } catch (Exception ee) {
        }
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException ex) {
            logger.error("Exception in closing InputStream in InventoryDBHelper", ex);
        }
    }
}

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

private int updatetMySqlNode(String nodeUuid, String asmType, String xsiType, String semantictag, String label,
        String code, String descr, String format, String metadata, String metadataWad, String metadataEpm,
        int sharedRes, int sharedNode, int sharedNodeRes, int modifUserId) throws Exception {
    String sql = "";
    PreparedStatement st;

    sql = "UPDATE node SET ";
    sql += "asm_type = ?,xsi_type = ?,semantictag = ?,label = ?,code = ?,descr = ?,format = ? ,metadata = ?,metadata_wad = ?, metadata_epm = ?,shared_res = ?,shared_node = ?,shared_node_res = ?, modif_user_id = ?,modif_date = ? ";
    sql += " WHERE node_uuid = uuid2bin(?) ";
    st = connection.prepareStatement(sql);

    st.setString(1, asmType);/*from   w  w  w.  ja  v  a  2  s  . c  om*/
    st.setString(2, xsiType);
    st.setString(3, semantictag);
    st.setString(4, label);
    st.setString(5, code);
    st.setString(6, descr);
    st.setString(7, format);

    st.setString(8, metadata);
    st.setString(9, metadataWad);
    st.setString(10, metadataEpm);

    st.setInt(11, sharedRes);
    st.setInt(12, sharedNode);
    st.setInt(13, sharedNodeRes);

    st.setInt(14, modifUserId);
    if (dbserveur.equals("mysql")) {
        st.setString(15, SqlUtils.getCurrentTimeStamp());
    } else if (dbserveur.equals("oracle")) {
        st.setTimestamp(15, SqlUtils.getCurrentTimeStamp2());
    }
    st.setString(16, nodeUuid);

    return st.executeUpdate();
}

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

private int updateMysqlResource(String uuid, String xsiType, String content, int userId) {
    String sql = "";
    PreparedStatement st;

    try {//  www.j  ava 2s  . c  o  m
        if (xsiType != null) {
            if (dbserveur.equals("mysql")) {
                sql = "REPLACE INTO resource_table(node_uuid,xsi_type,content,user_id,modif_user_id,modif_date) ";
                sql += "VALUES(uuid2bin(?),?,?,?,?,?)";
            } else if (dbserveur.equals("oracle")) {
                sql = "MERGE INTO resource_table d USING (SELECT uuid2bin(?) node_uuid,? xsi_type,? content,? user_id,? modif_user_id,? modif_date FROM DUAL) s ON (d.node_uuid = s.node_uuid) WHEN MATCHED THEN UPDATE SET d.xsi_type = s.xsi_type, d.content = s.content, d.user_id = s.user_id, d.modif_user_id = s.modif_user_id, d.modif_date = s.modif_date WHEN NOT MATCHED THEN INSERT (d.node_uuid, d.xsi_type, d.content, d.user_id, d.modif_user_id, d.modif_date) VALUES (s.node_uuid, s.xsi_type, s.content, s.user_id, s.modif_user_id, s.modif_date)";
            }
            st = connection.prepareStatement(sql);
            st.setString(1, uuid);
            st.setString(2, xsiType);
            st.setString(3, content);
            st.setInt(4, userId);
            st.setInt(5, userId);
            if (dbserveur.equals("mysql")) {
                st.setString(6, SqlUtils.getCurrentTimeStamp());
            } else if (dbserveur.equals("oracle")) {
                st.setTimestamp(6, SqlUtils.getCurrentTimeStamp2());
            }

            return st.executeUpdate();
        } else {
            sql = "UPDATE  resource_table SET content = ?,user_id = ?,modif_user_id = ?,modif_date = ? WHERE node_uuid = uuid2bin(?) ";

            st = connection.prepareStatement(sql);

            st.setString(1, content);
            st.setInt(2, userId);
            st.setInt(3, userId);
            if (dbserveur.equals("mysql")) {
                st.setString(4, SqlUtils.getCurrentTimeStamp());
            } else if (dbserveur.equals("oracle")) {
                st.setTimestamp(4, SqlUtils.getCurrentTimeStamp2());
            }
            st.setString(5, uuid);

            return st.executeUpdate();
        }

    } catch (Exception ex) {
        //System.out.println("root_node_uuid : "+uuid);
        ex.printStackTrace();
        return -1;
    }
}

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

public int updateMysqlFile(String nodeUuid, String lang, String fileName, String type, String extension,
        int size, byte[] fileBytes, int userId) {
    String sql = "";
    PreparedStatement st;

    try {/*from   w ww .j a v  a  2 s .  c  o  m*/
        if (dbserveur.equals("mysql")) {
            sql = "REPLACE INTO file_table(node_uuid,lang,name,type,extension,filesize,filecontent,modif_user_id,modif_date) ";
            sql += "VALUES(uuid2bin(?),?,?,?,?,?,?,?,?)";
        } else if (dbserveur.equals("oracle")) {
            sql = "MERGE INTO file_table d USING (SELECT uuid2bin(?) node_uuid,? lang,? name,? type,? extension,? filesize,? filecontent,? modif_user_id,? modif_date FROM DUAL) s ON (d.node_uuid = s.node_uuid AND d.lang = s.lang) WHEN MATCHED THEN UPDATE SET d.name = s.name, d.type = s.type, d.extension = s.extension, d.filesize = s.filesize, d.filecontent = s.filecontent, d.modif_user_id = s.modif_user_id, d.modif_date = s.modif_date WHEN NOT MATCHED THEN INSERT (d.node_uuid, d.lang, d.name, d.type, d.extension, d.filesize, d.filecontent, d.modif_user_id, d.modif_date) VALUES (s.node_uuid, s.lang, s.name, s.type, s.extension, s.filesize, s.filecontent, s.modif_user_id, s.modif_date)";
        }
        st = connection.prepareStatement(sql);
        st.setString(1, nodeUuid);
        st.setString(2, lang);
        st.setString(3, fileName);
        st.setString(4, type);
        st.setString(5, extension);
        st.setInt(6, size);
        st.setBytes(7, fileBytes);
        st.setInt(8, userId);
        if (dbserveur.equals("mysql")) {
            st.setString(9, SqlUtils.getCurrentTimeStamp());
        } else if (dbserveur.equals("oracle")) {
            st.setTimestamp(9, SqlUtils.getCurrentTimeStamp2());
        }

        return st.executeUpdate();

    } catch (Exception ex) {
        //System.out.println("root_node_uuid : "+uuid);
        ex.printStackTrace();
        return -1;
    }
}

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

private int insertMysqlPortfolio(String portfolioUuid, String rootNodeUuid, int modelId, int userId) {
    String sql = "";
    PreparedStatement st;

    try {/*from  w  ww  .j a v a2 s .  c om*/
        if (dbserveur.equals("mysql")) {
            sql = "REPLACE INTO portfolio(portfolio_id,root_node_uuid,user_id,model_id,modif_user_id,modif_date) ";
            sql += "VALUES(uuid2bin(?),uuid2bin(?),?,?,?,?)";
        } else if (dbserveur.equals("oracle")) {
            sql = "MERGE INTO portfolio d USING (SELECT uuid2bin(?) portfolio_id,uuid2bin(?) root_node_uuid,? user_id,? model_id,? modif_user_id,? modif_date FROM DUAL) s ON (d.portfolio_id = s.portfolio_id) WHEN MATCHED THEN UPDATE SET d.root_node_uuid = s.root_node_uuid, d.user_id = s.user_id,d.model_id = s.model_id, d.modif_user_id = s.modif_user_id, d.modif_date = s.modif_date WHEN NOT MATCHED THEN INSERT (d.portfolio_id, d.root_node_uuid, d.user_id, d.model_id, d.modif_user_id, d.modif_date) VALUES (s.portfolio_id, s.root_node_uuid, s.user_id, s.model_id, s.modif_user_id, s.modif_date)";
        }
        st = connection.prepareStatement(sql);
        st.setString(1, portfolioUuid);
        st.setString(2, rootNodeUuid);
        st.setInt(3, userId);
        if (dbserveur.equals("mysql")) {
            st.setInt(4, modelId);
        } else if (dbserveur.equals("oracle")) {
            st.setString(4, String.format("%32s", Integer.toHexString(modelId)).replace(' ', '0'));
        }
        st.setInt(5, userId);
        if (dbserveur.equals("mysql")) {
            st.setString(6, SqlUtils.getCurrentTimeStamp());
        } else if (dbserveur.equals("oracle")) {
            st.setTimestamp(6, SqlUtils.getCurrentTimeStamp2());
        }

        return st.executeUpdate();

    } catch (Exception ex) {
        System.out.println("root_node_uuid : " + rootNodeUuid);
        ex.printStackTrace();
        return -1;
    }
}

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

private int insertMysqlResource(String uuid, String parentUuid, String xsiType, String content,
        String portfolioModelId, int sharedNodeRes, int sharedRes, int userId) {
    String sql = "";
    PreparedStatement st;

    try {/*from  w  ww  .j av  a 2 s .  co m*/
        if (((xsiType.equals("nodeRes") && sharedNodeRes == 1)
                || (!xsiType.equals("context") && !xsiType.equals("nodeRes") && sharedRes == 1))
                && portfolioModelId != null) {
            // On ne fait rien

        } else {
            if (dbserveur.equals("mysql")) {
                sql = "REPLACE INTO resource_table(node_uuid,xsi_type,content,user_id,modif_user_id,modif_date) ";
                sql += "VALUES(uuid2bin(?),?,?,?,?,?)";
            } else if (dbserveur.equals("oracle")) {
                sql = "MERGE INTO resource_table d USING (SELECT uuid2bin(?) node_uuid,? xsi_type,? content,? user_id,? modif_user_id,? modif_date FROM DUAL) s ON (d.node_uuid = s.node_uuid) WHEN MATCHED THEN UPDATE SET d.xsi_type = s.xsi_type, d.content = s.content, d.user_id = s.user_id, d.modif_user_id = s.modif_user_id, d.modif_date = s.modif_date WHEN NOT MATCHED THEN INSERT (d.node_uuid, d.xsi_type, d.content, d.user_id, d.modif_user_id, d.modif_date) VALUES (s.node_uuid, s.xsi_type, s.content, s.user_id, s.modif_user_id, s.modif_date)";
            }
            st = connection.prepareStatement(sql);
            st.setString(1, uuid);
            st.setString(2, xsiType);
            st.setString(3, content);
            st.setInt(4, userId);
            st.setInt(5, userId);
            if (dbserveur.equals("mysql")) {
                st.setString(6, SqlUtils.getCurrentTimeStamp());
            } else if (dbserveur.equals("oracle")) {
                st.setTimestamp(6, SqlUtils.getCurrentTimeStamp2());
            }

            st.executeUpdate();
        }
        // Ensuite on met  jour les id ressource au niveau du noeud parent
        if (xsiType.equals("nodeRes")) {
            sql = " UPDATE node SET res_res_node_uuid =uuid2bin(?), shared_node_res_uuid=uuid2bin(?) ";
            sql += " WHERE node_uuid = uuid2bin(?) ";
            st = connection.prepareStatement(sql);
            st.setString(1, uuid);
            if (sharedNodeRes == 1 && portfolioModelId != null)
                st.setString(2, uuid);
            else
                st.setString(2, null);
            st.setString(3, parentUuid);
        } else if (xsiType.equals("context")) {
            sql = " UPDATE node SET res_context_node_uuid=uuid2bin(?)";
            sql += " WHERE node_uuid = uuid2bin(?) ";
            st = connection.prepareStatement(sql);
            st.setString(1, uuid);
            st.setString(2, parentUuid);
        } else {
            sql = " UPDATE node SET res_node_uuid=uuid2bin(?), shared_res_uuid=uuid2bin(?) ";
            sql += " WHERE node_uuid = uuid2bin(?) ";
            st = connection.prepareStatement(sql);
            st.setString(1, uuid);
            if (sharedRes == 1 && portfolioModelId != null)
                st.setString(2, uuid);
            else
                st.setString(2, null);
            st.setString(3, parentUuid);
        }

        return st.executeUpdate();
    } catch (Exception ex) {
        //System.out.println("root_node_uuid : "+uuid);
        ex.printStackTrace();
        return -1;
    }
}

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

private int updateMysqlResourceByXsiType(String nodeUuid, String xsiType, String content, int userId) {
    String sql = "";
    PreparedStatement st;

    try {//w w w  . j a v a2  s  .  co m
        if (xsiType.equals("nodeRes")) {
            sql = " UPDATE resource_table SET content=?,user_id=?,modif_user_id=?,modif_date=? ";
            sql += " WHERE node_uuid IN (SELECT res_res_node_uuid FROM node ";
            sql += " WHERE node_uuid=uuid2bin(?))  ";

            /// Interptation du code (vive le hack... Non)
            Document doc = DomUtils.xmlString2Document(
                    "<?xml version='1.0' encoding='UTF-8' standalone='no'?><res>" + content + "</res>",
                    new StringBuffer());
            NodeList nodes = doc.getElementsByTagName("code");
            Node code = nodes.item(0);
            if (code != null) {
                Node codeContent = code.getFirstChild();
                String codeVal;
                if (codeContent != null) {
                    codeVal = codeContent.getNodeValue();
                    String sq = "UPDATE node SET code=? WHERE node_uuid=uuid2bin(?)";
                    st = connection.prepareStatement(sq);
                    st.setString(1, codeVal);
                    st.setString(2, nodeUuid);
                    st.executeUpdate();
                    st.close();
                }
            }
        } else if (xsiType.equals("context")) {
            sql = " UPDATE resource_table SET content=?,user_id=?,modif_user_id=?,modif_date=? ";
            sql += " WHERE node_uuid IN (SELECT res_context_node_uuid FROM node ";
            sql += " WHERE node_uuid=uuid2bin(?))  ";
        } else {
            sql = " UPDATE resource_table SET content=?,user_id=?,modif_user_id=?,modif_date=? ";
            sql += " WHERE node_uuid IN (SELECT res_node_uuid FROM node ";
            sql += " WHERE node_uuid=uuid2bin(?))  ";
        }
        st = connection.prepareStatement(sql);
        st.setString(1, content);

        st.setInt(2, userId);
        st.setInt(3, userId);
        if (dbserveur.equals("mysql")) {
            st.setString(4, SqlUtils.getCurrentTimeStamp());
        } else if (dbserveur.equals("oracle")) {
            st.setTimestamp(4, SqlUtils.getCurrentTimeStamp2());
        }
        st.setString(5, nodeUuid);
        // st.setString(6,xsiType);

        return st.executeUpdate();

    } catch (Exception ex) {
        //System.out.println("root_node_uuid : "+uuid);
        ex.printStackTrace();
        return -1;
    }
}

From source file:com.portfolio.data.provider.MysqlAdminProvider.java

private int insertMySqlNode(String nodeUuid, String nodeParentUuid, String nodeChildrenUuid, String asmType,
        String xsiType, int sharedRes, int sharedNode, int sharedNodeRes, String sharedResUuid,
        String sharedNodeUuid, String sharedNodeResUuid, String metadata, String metadataWad,
        String metadataEpm, String semtag, String semanticTag, String label, String code, String descr,
        String format, int order, int modifUserId, String portfolioUuid) {
    String sql = "";
    PreparedStatement st;

    try {/*ww  w. j  a  v  a  2 s . com*/
        if (nodeChildrenUuid == null) {
            nodeChildrenUuid = getMysqlNodeResultset(nodeUuid).getString("node_children_uuid");
        }
    } catch (Exception ex) {

    }

    try {
        if (dbserveur.equals("mysql")) {
            sql = "REPLACE INTO node(node_uuid,node_parent_uuid,node_children_uuid,node_order,";
            sql += "asm_type,xsi_type,shared_res,shared_node,shared_node_res,shared_res_uuid,shared_node_uuid,shared_node_res_uuid, metadata,metadata_wad,metadata_epm,semtag,semantictag,label,code,descr,format,modif_user_id,modif_date,portfolio_id) ";
            sql += "VALUES(uuid2bin(?),uuid2bin(?),?,?,?,?,?,?,?,uuid2bin(?),uuid2bin(?),uuid2bin(?),?,?,?,?,?,?,?,?,?,?,?,uuid2bin(?))";
        } else if (dbserveur.equals("oracle")) {
            sql = "MERGE INTO node d USING (SELECT uuid2bin(?) node_uuid,uuid2bin(?) node_parent_uuid,? node_children_uuid,? node_order,? asm_type,? xsi_type,? shared_res,? shared_node,? shared_node_res,uuid2bin(?) shared_res_uuid,uuid2bin(?) shared_node_uuid,uuid2bin(?) shared_node_res_uuid,? metadata,? metadata_wad,? metadata_epm,? semtag,? semantictag,? label,? code,? descr,? format,? modif_user_id,? modif_date,uuid2bin(?) portfolio_id FROM DUAL) s ON (d.node_uuid = s.node_uuid) WHEN MATCHED THEN UPDATE SET d.node_parent_uuid=s.node_parent_uuid,d.node_children_uuid=s.node_children_uuid,d.node_order=s.node_order,d.asm_type=s.asm_type,d.xsi_type=s.xsi_type,d.shared_res=s.shared_res,d.shared_node=s.shared_node,d.shared_node_res=s.shared_node_res,d.shared_res_uuid=s.shared_res_uuid,d.shared_node_uuid=s.shared_node_uuid,d.shared_node_res_uuid=s.shared_node_res_uuid,d.metadata=s.metadata,d.metadata_wad=s.metadata_wad,d.metadata_epm=s.metadata_epm,d.semtag=s.semtag,d.semantictag=s.semantictag,d.label=s.label,d.code=s.code,d.descr=s.descr,d.format=s.format,d.modif_user_id=s.modif_user_id,d.modif_date=s.modif_date,d.portfolio_id=s.portfolio_id WHEN NOT MATCHED THEN INSERT (d.node_uuid,d.node_parent_uuid,d.node_children_uuid,d.node_order,d.asm_type,d.xsi_type,d.shared_res,d.shared_node,d.shared_node_res,d.shared_res_uuid,d.shared_node_uuid,d.shared_node_res_uuid,d.metadata,d.metadata_wad,d.metadata_epm,d.semtag,d.semantictag,d.label,d.code,d.descr,d.format,d.modif_user_id,d.modif_date,d.portfolio_id) VALUES (s.node_uuid,s.node_parent_uuid,s.node_children_uuid,s.node_order,s.asm_type,s.xsi_type,s.shared_res,s.shared_node,s.shared_node_res,s.shared_res_uuid,s.shared_node_uuid,s.shared_node_res_uuid,s.metadata,s.metadata_wad,s.metadata_epm,s.semtag,s.semantictag,s.label,s.code,s.descr,s.format,s.modif_user_id,s.modif_date,s.portfolio_id)";
        }
        st = connection.prepareStatement(sql);
        st.setString(1, nodeUuid);
        st.setString(2, nodeParentUuid);
        st.setString(3, nodeChildrenUuid);
        st.setInt(4, order);
        st.setString(5, asmType);
        st.setString(6, xsiType);
        st.setInt(7, sharedRes);
        st.setInt(8, sharedNode);
        st.setInt(9, sharedNodeRes);
        st.setString(10, sharedResUuid);
        st.setString(11, sharedNodeUuid);
        st.setString(12, sharedNodeResUuid);
        st.setString(13, metadata);
        st.setString(14, metadataWad);
        st.setString(15, metadataEpm);
        st.setString(16, semtag);
        st.setString(17, semanticTag);
        st.setString(18, label);
        st.setString(19, code);
        st.setString(20, descr);
        st.setString(21, format);
        st.setInt(22, modifUserId);
        if (dbserveur.equals("mysql")) {
            st.setString(23, SqlUtils.getCurrentTimeStamp());
        } else if (dbserveur.equals("oracle")) {
            st.setTimestamp(23, SqlUtils.getCurrentTimeStamp2());
        }
        st.setString(24, portfolioUuid);

        return st.executeUpdate();

    } catch (Exception ex) {
        ex.printStackTrace();
        return -1;
    }
}