Sunday, 27 September 2015

Get all connected user session list in oracle and kill oracle session


Get list of session active in oracle

you can get the list of active session from v$session table;


select 'alter system kill session '''|| sid ||',', serial#||'''' from v$session;


Kill the active session in oracle 

below statement will kill the live session.

alter system kill session '325,250';


Tuesday, 22 September 2015

Convert csv to xml in java

Convert csv to xml in java

   here i have used opencsv-2.2.jar library for converting csv file into xml.

CsvToXmlConvert.java

package com.convert;

import java.io.File;
import java.io.FileReader;


import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import au.com.bytecode.opencsv.CSVReader;

public class CsvToXmlConvert {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        StringBuilder xml = new StringBuilder();
         String startFile = "/Book1.csv";
       
            try {
               
                File file=new File(request.getRealPath(startFile));
                CSVReader reader = new CSVReader(new FileReader(file));
               
                String[] line = null;
                String[] header = reader.readNext();
                Document doc = docBuilder.newDocument();
               
                Element rootElement = doc.createElement("Result");
                doc.appendChild(rootElement);
                Element Employees = doc.createElement("Employees");

                while((line = reader.readNext())!=null){
                   
                    Element Employee = doc.createElement("Employee");
                       
                    for (int i = 0; i < header.length; i++) {
                   
                        Element elm = doc.createElement(header[i].trim());
                        elm.appendChild(doc.createTextNode(line[i].trim()));
                        Employee.appendChild(elm);
                       
                    }
                       
                    Employees.appendChild(Employee);
                }
               
                rootElement.appendChild(Employees);
               
                TransformerFactory transformerFactory = TransformerFactory.newInstance();
                Transformer transformer = transformerFactory.newTransformer();
                DOMSource source = new DOMSource(doc);
                StreamResult result = new StreamResult(new File("/home/file.xml"));
                transformer.transform(source, result);
               
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }

}





CSV FILE FORMATE

Book1.csv

FirstName, LastName, Number
Pushpak, Khatri, 9999999999
Raj,Patel, 9999999999
Simran, Khanna, 9999999999



Sunday, 20 September 2015

Paging with oracle


Paging with Oracle


SELECT * FROM
(
    SELECT ID, rownum r__
    FROM
    (
        SELECT ID FROM SUBSCRIBER order by id) a
    WHERE rownum < ((:page * :pageSize) + 1 )
)
WHERE r__ >= (((:page-1) * :pageSize) + 1)

Friday, 4 September 2015

Merge two json/javascript arrays in to one array

Merge two json/javascript arrays in to one array



(function($){$.concat||$.extend({concat:function(b,c){var a=[];for(var x in arguments)if(typeof a=='object')a=a.concat(arguments[x]);return a}});})(jQuery);

$(function() {
    var json1 = [{id:1, name: 'xxx'}],
        json2 = [{id:2, name: 'xyz'}],
        json3 = [{id:3, name: 'xyy'}],
        json4 = [{id:4, name: 'xzy'}],
        json5 = [{id:5, name: 'zxy'}];
   
    console.log($.concat(json1, json2, json3))
    console.log($.concat(json1, json2, json3, json4, json5))
    console.log($.concat(json4, json1, json2, json5))
});