March 2008 - Posts

Just a quick post from me here. I couldn't find  any resources on the internet, I couldn't remember how I found this solution. Here's the scenerio.

When you try to parse and Excel sheet using JXLS, unless your Excel sheet column is formatted in General, you wouldn't be able to get the actual date format like mm/dd/yyyy. If your column is formatted to have a Date field, once you parse in JXLS you will get something like

39505 

All you have to do is pass that to  HSSFDateUtil (org.apache.poi.hssf.usermodel.HSSFDateUtil)'s , getJavaDate method like this...

HSSFDateUtil.getJavaDate( Double.parseDouble("39505") );

And it will give you a Date object that has the value 

Wed Feb 27 00:00:00 CST 2008

Remember that JXLS is just a wrapper for POI. POI is the real Excel Framework so you could still use POI classes. 

Busy busy busy

Posted by lamia | 2 comment(s)
Filed under: ,

Note: The code provided will not compile. It should only serve as a guide! 

We had a performance issue and one of the solutions I came to to prevent excessive rountrip from my Java application to the database is to pass the things I need as an array to a store procedure. I won't cover the Java part here as I won't be pushing with it anyway, I'm just posting here for other people's reference.

To warn you though, passing an Array from my App to a PL/SQL stored procedure made my code vendor-dependent(i.e. Websphere dependent).

Inside a PL/SQL Package, you have to declare a TYPE as a TABLE of your TYPE:

TYPE VARCHAR2_ARR  IS TABLE OF VARCHAR2(50);

Then, you can now use it as a parameter in your function/stored proc

PROCEDURE MY_PROC(MY_PARAM_ARR IN VARCHAR2_ARR)

IS

  --LOOP LIKE YOU WOULD LOOP INSIDE A CURSOR

   FOR TEMP_VAR IN MY_PARAM_ARR.FIRST .. MY_PARAM_ARR.LAST LOOP

    --USE TEMP_VAR HERE 

   END LOOP;
 

END  MY_PROC;

 

Now I'm gonna go for a comm-delimited approach for my parameter, parse that and see how it would benefit me. 

 

Posted by lamia | with no comments
Filed under:

Note: I'm doing this code inside a Package. I've never written an PL/SQL program outside of a Package. 

You can declare exception everywhere inside a PL/SQL Stored Procedure or Function. 

PROCEDURE MY_PROC(V_ARG_SOMETHING IN MY_TBL.MY_FIELD%TYPE)

 --SOMETHING CAUSE AN EXCEPTION HERE
 

EXCEPTION WHEN OTHERS THEN

 /*DO YOUR EXCEPTION HANDLING CODE HERE */

END  MY_PROC;

 

I found it useful though on some situation to wrap my exception handling code inside  a BEGIN - END block

PROCEDURE MY_PROC(V_ARG_SOMETHING IN MY_TBL.MY_FIELD%TYPE)

   BEGIN 

     --SOMETHING CAUSE AN EXCEPTION HERE

     EXIT; --IF CODE FINISHES
 

     EXCEPTION WHEN OTHERS THEN

        /*DO EXCEPTION HANDLING HERE*/ 

   END ;

 

EXCEPTION WHEN OTHERS THEN

 /*DO YOUR EXCEPTION HANDLING CODE HERE */

END  MY_PROC;

My team lead complimented me that I'm becoming an expert on this. And it felt really nice. :)

Posted by lamia | with no comments
Filed under:

We downloaded our project from JDK 1.5 to JDK 1.4. The step would obviously bring out some issues and the most annoying one I've come to experience so far is when I couldn't open my ejb-jar in the deployment descriptor editor.

The solution was quite tricky. In RAD7, I had to go through the "Resource" perspective and then open the .settings folder. Inside the folder there's a file called org.eclipse.wst.commmon.component. Open that file and make sure your entries look like the following...

 <?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="YOURPROJECT>
        <wb-resource deploy-path="/" source-path="/ejbModule"/>
        <property name="java-output-path" value="ejbModule"/>
    </wb-module>
</project-modules>

 

I'm not sure if the same problem can be encountered in Eclipse, but for sure it would be a close if not similar solution. 

Posted by lamia | with no comments
Filed under: ,

 I had a session-scoped session form and when a user clicks on a button, I wanted the value to be reset. I tried to do something like

 

myForm.setValue("");

 

but it didn't do the job for some reason. Of course, I'm doing the usual struts way of getting the form by casting the ActionForm down to my specific type. It seems that overrding the reset() method was a more effective way in my case... The reset method has the signature

public void reset(ActionMapping mapping, HttpServletRequest request) {

//reset your fields here 

This is basic stuff, but sometimes when  you get to do more advanced things with your tools we often neglect the most basic of things... 

Posted by lamia | 1 comment(s)
Filed under: