31 May 2020

Geeky way to copy data between laptops which are in same network

Guys

Recently, I had a requirement to copy data from a laptop with disabled USB ports to a laptop which was normal 😉.
Since , I could not have used a pen drive to transfer data, so, I wrote a simple java socket program which served my purpose beautifully. Of-course, already available FTP client/server apps would have proven handy but what's fun in that!

PS: I hope it is self-explanatory that I didn't have the privileges to change the WORK-GROUP/DOMAIN of a laptop whose USB ports were disabled 

In case you tick any of the below criteria , then , you could use my code

1. USB ports are disabled on a laptop.
2. You are not a great admirer of FTP protocol 😄
3. You recently lost a pen drive
4. You can't change the WORK-GROUP/DOMAIN of a laptop.
5. You want to learn java socket programming
6. You are curious
7. You want to submit it as your semester project assignment.

Click here to get the deliverable.

In case , you want to see source code , DM me.









Delicious add to del.icio.us saved by 0 users

07 March 2014

Getting introduced to Spring...where to start..

For an introduction to Spring...please refer to this url...
http://docs.spring.io/docs/Spring-MVC-step-by-step/

Pom file example to download spring dependencies in Maven 
pom_spring




Delicious add to del.icio.us saved by 0 users

06 January 2013

All about oracle Jobs

This is how a basic job is written :

BEGIN
  DBMS_SCHEDULER.create_job (
    job_name        => 'myJob', 
    job_type        => 'PLSQL_BLOCK',
    job_action      => 'BEGIN procedure_name ; END;',
    start_date      => SYSTIMESTAMP,
    repeat_interval => 'freq=hourly; byminute=0; bysecond=0;',
    end_date        => NULL,
    enabled         => TRUE,
    comments        => 'Job defined entirely by the CREATE JOB procedure.');
END;

Note :  Other types of repeat_interval 
repeat_interval => 'freq=weekly; BYDAY=sun; byhour=8; byminute=0',
repeat_interval  =>  'FREQ=SECONDLY;INTERVAL=10',



This is how job details can be seen :

SELECT * FROM dba_scheduler_jobs;
 
Stopping job :
 
BEGIN
DBMS_SCHEDULER.STOP_JOB('procedure_name,job_class');  
END;
  
Job class can been seen from "dba_scheduler_jobs"  table.

For dropping job use  => DBMS_SCHEDULER.DROP_JOB('procedure_name,job_class');

For disabling job use => DBMS_SCHEDULER.DISABLE('procedure_name,job_class');
For enabling job use => DBMS_SCHEDULER.ENABLE ('procedure_name,job_class'); 





for more info use links : 

Link1
Link2




Delicious add to del.icio.us saved by 0 users

30 November 2012

code to check if the string contains all digits or not

Long checkDataType(String s){

char c[]=s.toCharArray();
boolean isnum=true;

for(int i=0;i
     if(!Character.isDigit(c[i])){

    isnum=false;

    break;

  }

}

if(isnum)

return (Long.parseLong(s));

else

return null;

}




Delicious add to del.icio.us saved by 0 users

06 November 2012

All about XPath

this is the sample xml.


DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
dom = db.parse("C:/templates.xml");

 XPath xpath=XPathFactory.newInstance().newXPath();
 XPathExpression expr=xpath.compile("//templates/template[1]/label/text()");
 NodeList ns=(NodeList)expr.evaluate(dom,XPathConstants.NODESET);

 for(int i=0;i    {
        System.out.println(ns.item(i).getNodeValue());

 }

here the output will be the value of the label of 1st template tag.



XPathExpression expr=xpath.compile("//templates/template/label/text()");
  NodeList ns=(NodeList)expr.evaluate(dom,XPathConstants.NODESET);

here the output will be the value of all the labels present in all the template tags


XPathExpression expr=xpath.compile("//templates/template/@name");
NodeList ns=(NodeList)expr.evaluate(dom,XPathConstants.NODESET);

here the output will be the values of attribute name of all the template tags



 XPathExpression expr=xpath.compile("//templates/template");
 NodeList ns=(NodeList)expr.evaluate(dom,XPathConstants.NODESET);
    for(int i=0;i       NamedNodeMap la=ns.item(i).getAttributes();
    System.out.println(la.getNamedItem("name").getNodeValue());

}

if a tag has more than 1 attribute, then , values of the attributes can be fetched like this.


  XPathExpression expr=xpath.compile("//templates/template/@name");
    NodeList ns=(NodeList)expr.evaluate(dom,XPathConstants.NODESET);
    for(int i=0;i         ns.item(i).setNodeValue("this is test");
         Transformer xformer = TransformerFactory.newInstance().newTransformer();
         xformer.transform(new DOMSource(dom), new StreamResult(new File("C:/templates.xml")));
    }


This code is changing the value of the specified attribute,here the attribute name is 'name' and saving in the xml





Delicious add to del.icio.us saved by 0 users

02 November 2012

calling procedure and functon from java code

calling stored procedure :

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


String s;
 String stmt="{call test(?)}";
 System.out.println(stmt);
 CallableStatement cs=con.prepareCall(stmt);
 System.out.println("enter the name of the employee");
 s=br.readLine();
 cs.setString(1,s);
 cs.execute();


calling function:

String stmt="{?=call test_fn(?)}";

String stmt="select test_fn('abc') from dual";
CallableStatement cs=con.prepareCall(stmt);
System.out.println("enter the name of the employee");
s=br.readLine();
cs.registerOutParameter(1,java.sql.Types.INTEGER);
cs.setString(2,s);
cs.execute();


to retrieve value
cs.getInt(1) ,so, in general , cs.get(Type)(index)


also instead of  "java.sql.Types.INTEGER", "oracle.jdbc.driver.OracleTypes.INTEGER" can be used.




Delicious add to del.icio.us saved by 0 users

30 October 2012

dom parser

package check;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;



public class DOM_Demo {

Document dom;

public static void main(String[] args) throws Exception {

new DOM_Demo().go();

}


void ret(Node d){

NodeList n=d.getChildNodes();

{
System.out.println(d.getNodeName());
for@(int i=0;i{
    if(n.item(i).getNodeType()==1)  // 1 IS THE VALUE FOR TAG

ret(n.item(i));

}
else

{

if(n.item(i).getNodeValue().trim().length()!=0)
System.out.println("val : "+n.item(i).getNodeValue());
}

}


}

}

void go() throws Exception

{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//Using factory get an instance of document builder

DocumentBuilder db = dbf.newDocumentBuilder();
//parse using builder to get DOM representation of the XML file

dom = db.parse("C:/Users/shasharm/Desktop/ibf/NS_ABIS_IRP_IP_E1.xml");

Element d = dom.getDocumentElement();

ret(d);

}

}





Delicious add to del.icio.us saved by 0 users