Friday, March 27, 2015

Learnings on FTPClient class of Apache

Exploration is very good for a person but sometimes there wouldn't be a proper location where you get what you need. This was one of those instances in my exploration phase and hence I would like to share the learnings of FTPClient class.

Problem Statement : ftpClientObject.getTimestamp() is not returning time in seconds field.

Explanation :

My code is something like below,

private static void getFTPFileProperties(FTPClient client,
            String ftpLocation, String pattern) throws IOException {
    FTPFile[] fileList=null;
    fileList = client.listFiles();
    for(int i=0;i<fileList.length;i++)
    {
        FTPFile file= fileList[0];
        Calendar cal = file.getTimestamp();
        DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(dateFormater.format(cal.getTime()));
    }
}
From the above, variable cal is should ideally retrieve timestamp which will be having even seconds field. But somehow I am able to view the date part and only the hours part. The timestamp is carrying 00 in minutes and also in seconds.

Myself being helpless posted this question in stackoverflow and thankfully Martin has caught my problem absolutely right.

Reason : listFiles() will function something like ls command of unix and thus it might not retrieve the entire timestamp part. It is suggested to use mlistDir() function in order to get the entire timestamp. But only condition the method mlistDir is defined in Apache Commons 3.0 version and I was using Commons 2.0 which was the problem. The moment I changed it to Apache Commons 3.0 it started working.

There is also a function client.getModificationTime("upload/01%20(160).jpg"); which might give the same result but this also has limitations when Commons 2.0 is used.

http://www.programdevelop.com/1506369/ would make you understand what is the problem.

Thanks to Martin who has helped me in addressing my issue and thanks to stack overflow in helping me post it.

Reference :

http://stackoverflow.com/questions/29300686/ftpclient-listfiles-is-not-returning-time-in-seconds 

Tuesday, March 24, 2015

Get Amount in words from query : SQL Developer

Below query helps you get the amount in words and also in camel case

SELECT INITCAP(TO_CHAR(TO_DATE(ROUND(AMOUNT),'J'),'JSP')) AS AMOUNT_WORDS_CAMEL_CASE FROM DH_EXPLORATION;

Below screenshot is self explanatory,



In the query mentioned, TO_DATE is used to get the amount in words and INITCAP is used to get the amount in words as camel case.

Learnings : From GIB  

Sunday, March 15, 2015

Auto Login into windows user accounts

The user account in any computer is a security measure but we tend to be always in a situation where we are sure that only we will be using and at time this security measure might become a bit tedious thing. So in order to remove this user Id login situation we can make achieve this using windows functionality,

Padding 0's in XSLT

I want a string to be fixed to 10 digits and pad 0's if it is less than length 10. This I have to achieve in XSLT here is how we can do it,

substring(concat("0000000000",string(//b/text())),string-length(//b/text())+1)

Assuming //b will have the string which is to be formatted.

Where as the same can be achieved using String functions in java,

String.format("%010d", 1236)




Friday, March 13, 2015

Change default program from command line

Sometime we wont be able to open an executable jar using default program after some infinite attempts using "open with". I have faced similar problem as there is a jar which I have to open using javaw.exe and somehow I was unable to. So here is what I have did,

I have changed the default program of jarfile using command line and awesome thing is "IT WORKED" :P

here is the command,

 
And then I opened the jar and It worked,


Monday, March 9, 2015

How to change oracle user's password if it is expired

Problem statement : I am trying to connect to database using sql developer and it throwed an error saying "the password has expired" and I find it really difficult to change the password from oracle homepage (ver 11).

Resolution : Open the oracle client and connect using your username and password.  It will automatically ask for change password.

Strange thing is there are no password policies at all. You can keep the old password itself for new password :P