Wednesday, July 27, 2016

Compare Text in 2 files and write the difference in a new file

Here I am reading 2 files, first file data is added to list.second file data is added to another list.Then converting 2 list to 2 Hashset. Then i am removing 1st hashset from the 2nd one.In this process all the common string will get removed and the new Hashset will have the difference data.
 * Getting 2 text files with single column data in each, need to find out the difference and write the difference between the 2 files to a new file.
public class CompareTwoFiles {
public static List readcsv(String filename) {
List l=new ArrayList();
String tempstr = "";
String dataStr = "";
int rownum = 0;
try {
BufferedReader br = new BufferedReader(new FileReader(filename));
try {
String line = "";
while ((line = br.readLine()) != null) {
// System.out.println(dataStr);
} catch (IOException e) {
// TODO Auto-generated catch block
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
return l;

   public CompareTwoFiles() {
       // TODO Auto-generated constructor stub

   public static void writecsv(String str,String filename){
FileWriter fileWriter = null;
       try {
fileWriter = new FileWriter("E://"+filename+"_DIFF.txt");
       } catch (Exception e) {
System.out.println("Error in CsvFileWriter !!!");
} finally {

try {
} catch (IOException e) {
System.out.println("Error while flushing/closing fileWriter !!!");


   public static void main(String[] args) {

   List ls1 = readcsv("E://TEMPLATE.txt");
   List ls2 = readcsv("E://SETSHEET.txt");
   Set set1 = new HashSet();
   Set set2 = new HashSet();
   String str="";
   for (String diffElement : set2) {

Thursday, June 30, 2016

Capture AJAX response and assign to a variable using JQUERY

function checkforduplicateempname(){
 var message=true;
 /*Assigning AJAX response to a javascript variable*/
 var empId = $.ajax({
   url: 'checkforduplicateempname.relay',
   data: oMyForms,
   cache: false,
   contentType: false,
   processData: false,
   global: false,
   type: 'POST',
   success: function(data){
    return data;
    $("#empname").notify("Unable to check for duplicate title.","error");
}).responseText; //end of ajax capturing the response
    $("#empaname").notify("Duplicate Title.","error");

return message;
}//end of function

Sunday, January 17, 2016

How to retain the space of the td after hidding it in Jquery

If you use the following code snippet to hide and show tds- the UI will get disturbed.
The next corresponding td will get shifted to the hidden td space.
  var tablevar="#"+myTable;
 $(tablevar+' tr:eq('+i+')').find('td:eq(3)').show();
   $(tablevar+' tr:eq('+i+')').find('td:eq(2)').show();

So how to retain the td space and still achieve the functionality.
use the this code snippet.
  var tablevar="#"+myTable;
$(tablevar+' tr:eq('+i+')').find('td:eq(3)').css("visibility", "hidden");
 $(tablevar+' tr:eq('+i+')').find('td:eq(2)').css("visibility", "hidden");

 $(tablevar+' tr:eq('+i+')').find('td:eq(4)').css("visibility", "visible");

Thursday, August 20, 2015

How to extend a JSON array in Jquery

Suppose you get a JSON  Object like this

var optionsoptions;
 $.getJSON("relaytemplateattributes.json" , function(result){

{"OPTIONID":2,"COMBOITEM":"0 deg"},{"OPTIONID":2,"COMBOITEM":"180 deg"}
{"OPTIONID":3,"COMBOITEM":"1 out of 3"},{"OPTIONID":3,"COMBOITEM":"2 out of 3"},
{"OPTIONID":3,"COMBOITEM":"3 out of 3"},{"OPTIONID":4,"COMBOITEM":"4"},
{"OPTIONID":5,"COMBOITEM":"2 out of 3"}}

if you want to append to new value to optionsoptions Object you can extend the optionsoptions Object in jquery.

 var object3 = {
    "COMBOITEM": $("#newoptionValue3").val()
    $.extend( optionsoptions, object3);

Friday, February 20, 2015

Jquery Table Inline Edititing

The Above link demonstrates inline editing of jquery.
The  idea used to implement  is as follows:

Table consists of two identical rows  first one is Parent row which is non editable
Second one is Editable child row.
By Default the Parent row is visible and on click on edit the parent row is hidden and child row is displayed.
Save data displays all the modified row records and it stores it in a hidden string.

Wednesday, December 24, 2014

Convert Excel to XML in JEXCEL API



import jxl.*;
import jxl.demo.XML;

import java.util.*;

import java.sql.*;

public class ExceltoXML{

// public void readExcelFile() {
public static void main(String args[]) throws BiffException, IOException{
File f = new File("TestConsolidated.xml");
OutputStream os = (OutputStream) new FileOutputStream(f);
String encoding = "UTF8";
OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
String filename = "relaytemplate.xls";
WorkbookSettings ws = new WorkbookSettings();
ws.setLocale(new Locale("en", "EN"));
Workbook w = Workbook.getWorkbook(new File(filename), ws);
try {
XML myxml=new XML(w,os,filename, false);
} catch (IOException e) {
// TODO Auto-generated catch block

Wednesday, December 10, 2014

Spring JDBC Template- To get back the inserted values using Keyholder

public List insert(final Action action){
KeyHolder holder = new GeneratedKeyHolder();
jdbcTemplate.update(new PreparedStatementCreator() {           

                public PreparedStatement createPreparedStatement(Connection connection)
                        throws SQLException {
                    PreparedStatement ps = connection.prepareStatement(insertIntoSql.toString(), Statement.RETURN_GENERATED_KEYS);
                    ps.setString(1, action.getAction_name());
                    return ps;
            }, holder);

KeyHolder newPersonId = holder;
return newPersonId.getKeyList();