Friday, April 23, 2010

Encrypt, Decrypt password in Mysql

Inserting password encrypted to database using the following sql.

INSERT INTO PASSWORD(pass) VALUES(DES_ENCRYPT('user password')); 

This SQL will encrypt the user inserted password to a encrypted text. In table level, password is unreadable.
Instead of DES_ENCRYPT() method you can come up with your own function.

Selecting password from database to a string.

SELECT DES_DECRYPT(pass) FROM PASSWORD ;

This SQL will return user password as user inserted.



Monday, March 29, 2010

weblogic.xml to use on memory session replication

<?xml version="1.0" encoding="UTF-8" ?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<session-descriptor>
<timeout-secs>300</timeout-secs>
<invalidation-interval-secs>60</invalidation-interval-secs>
<persistent-store-type>jdbc</persistent-store-type>
<persistent-store-pool>SessionDS</persistent-store-pool>
<persistent-store-table>WL_SERVLET_SESSIONS</persistent-store-table>
</session-descriptor>
</weblogic-web-app>

Use the above code for weblogic.xml. Your weblogic cluster MUST be configured to use jdbc persistence store to capture web-browsers and nodes sessions. WL_SERVLET_SESSIONS is the table for session store.

Add this weblogic.xml file to your WEB-INF directory and deploy your application to the weblogic cluster. When a cluster node down, it will replicate all the JSP sessions associates with the clients.

Sunday, March 14, 2010

Add your own jars to weblogic application

Sometimes weblogic server uses its server lib .jars. If you want your application to use your own versions of .jar files, add following code to your weblogic.xml file located in WEB-INF directory.

<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>

This will use libraries in your application.

Thursday, February 25, 2010

Java Application Memory utilization

java -jar -Xms64m -Xmx128m Test.jar

When running your java application, use above arguments. This will allocate 64MB minimum for your application and 128MB maximum. If 128MB exceeds, java will call the garbage collector.

Wednesday, February 10, 2010

Writing console output to a file in java

Use this code to write your console outputs to a file using java.

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

public class RedirectIO {

public static void main(String[] args) {

PrintStream orgStream = null;
PrintStream fileStream = null;

try {

// Saving the orginal stream
orgStream = System.out;
fileStream = new PrintStream(new FileOutputStream("d:/123.txt",true));

// Redirecting console output to file
System.setOut(fileStream);

// Redirecting runtime exceptions to file
System.setErr(fileStream);

throw new Exception("Test Exception");

}catch (FileNotFoundException fnfEx){
System.out.println("Error in IO Redirection");
fnfEx.printStackTrace();
}catch (Exception ex){
ex.printStackTrace();
//Gets printed in the file
System.out.println("Redirecting output & exceptions to file");
}finally{
//Restoring back to console
System.setOut(orgStream);
//Gets printed in the console
System.out.println("Redirecting file output back to console");
}
}
}

Saturday, February 6, 2010

Stack Trace of the Exception to a String

Use this code inside your catch block. This will return a string.

}catch(Exception e){

StringWriter sWriter = new StringWriter();
e.printStackTrace(new PrintWriter(sWriter));
System.out.println(sWriter.getBuffer().toString()) ;

}

Tuesday, February 2, 2010

Task Manager in Solaris Console

In console type "prstat".

This will show a program looks like windows Task manager.