May 29

Back to my beautiful bungalow in Saidapet — filled with dust and love. Sister’s marriage got over. Be back in chennai office on Thursday. This also means the restart of scribbling on this big sheet of paper.

And if you really wanted to ask what i learnt these days, here are sample pics

Dont beat around the bush

Water is scarce (to the throat at least)

Looks are deceptive

THE GRASS IS ALWAYS GREENER ON THE OTHER SIDE OF THE FENCE

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis

Tags:

May 18

I feel ashamed to tell that I am just now putting my head into learning Lucene.  “Never too late”, I am trying to tell to myself.

Here is one beautiful tutorial on Lucene.

Tutorial by Steven J Owens

Please do refer to this page too 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis

Tags:

May 18

Expandable sample

Say, you have an expandable menu (like the one in picture but the expansion is not Javascript driven) on the parent window and the parent window refreshes on every click of the node of the menu (the (+) and (-) kind of menus). You also have a “Close All” button on the parent window which is supposed to close all the child windows.

Ideally, you want to hold the names (or handles) of the child windows in order to close all the child windows when the “Close all” button is pressed. But since the parent window gets refreshed on menu node expansion, the Javascript array of child handles that i have disappears.

Bottom line, Javascript variables get reinitialized on page refreshes. But there is a workaround for this.

You can simply assign the array to a special variable called navigator.storedvariable

Something like,
navigator.storedvariable=windowNames; // windowNames is the array of names of the child windows.

This is the exact code i wrote for implementing the Closeall functionality

function closeChildWindows(){//retrieve all the names of childwindows
var childWindows = navigator.storedvariable;
if ( childWindows != null ){

//loop through each of the window
for (var k=0;k<childWindows.length;k++){
var openedWindowName = childWindows[k];

//Open all the child windows since we have already lost handles and then close again. The browser will open the child window in the same previous (stale) browser child window

winHandle = window.open(”,openedWindowName,’toolbar=0,location=0,width=2,height=2,scrollbars=no,resizable=no,directories=0,status=0,menubar=0′);winHandle.blur();
//as soon as you open, close them. So that the user doesnt realise that the same browser was used again

if( winHandle && winHandle.open && !winHandle.closed)
{
winHandle.close();
}
}//end of for loop

} // end of childwindows!= null
//after closing all windows, reinitialize navigator.storedvariable
windowNames=new Array();
navigator.storedvariable=windowNames;
}

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis

Tags:

May 11

I happen to face this problem a year back.  I was expected to show an image on a JSP which is stored as a BLOB in the database.  (I also wrote another post a few days back with uploading and showing image from a MySQL database (with Hibernate)).  The problem I faced a year back was that i was displaying junk values on the page instead of the image though the MIME type was set as “image/jpeg” and  the output stream flushed.

The same kind of problem my friend faced last week when he was trying to extract information from the database and export it as excel sheet.  He used Apache POI for constructing the workbook, set the MIME type as “application/vnd.ms-excel” and flushed the output stream. But what got exported was just junk values.

The reason was that only the ServletOutputStream was flushed out. Not the response. As you already know that in Servlets, the response does not get flushed automatically (unlike JSPs). So, here comes the need for response.flushBuffer();

Here is the core code.

response.reset();

response.setContentType(“application/vnd.ms-excel”);response.addHeader(“Content-Disposition”,“filename=TableList.xls”);

 

ServletOutputStream stream=response.getOutputStream();

wb.write(stream);

 

//flush output stream

stream.flush();

 

//please dont forget to flush the response

response.flushBuffer();

 

//need to close the stream now. .

 

stream.close();

I developed a small sample application. Please dont mind the architecture or performance of the code. Download the entire source code.

Please note that I have not defined any welcome-files. Point your browser to export.jsp. (PS :Application works only against Oracle databases) 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis

Tags: , , , , ,

May 10

As you know, Java 6.0 comes bundled with Apache Derby.  The “db” folder inside the JDK 6.0 directory is our bundled Database. Here is the list of things i did on the db.

1) Connect 

    But before connecting we need to set the classpath for Apache Derby. Just add the following lines to your classpath.

     $JAVA_HOME\db\lib\derby.jar;$JAVA_HOME\db\lib\derbytools.jar;

    Basically, the derby.jar is the core apache derby db purely written in Java. (comes around 2 MB).  More on Apache Derby >>

    And the derbytools.jar gives one interesting tool called the “ij” for that command line db access.

      java org.apache.derby.tools.ij  will give you a “ij” prompt.  Type help and you will get a list of commands you can play with.

      ij> help;

ij help list of commands

      Finally, to connect to a database, use the following command.

      connect ‘jdbc:derby:myfirstdb;create=true’;

     The String following the “connect” keyword just tells us that you are using org.apache.derby.jdbc.EmbeddedDriver (jdbc:derby) to connect to myfirstdb (your database), which has not been created yet. So you create it (create=true).  So, the next time you want to connect to the same database, connect ‘jdbc:derby:myfirstdb’ ; will do.

2) Create table

ij> show tables;

TABLE_SCHEM |TABLE_NAME |REMARKS

————————————————————————

0 rows selected

ij> create table emp (empname varchar(20), empno int);

0 rows inserted/updated/deleted

3) Insert a row to table and query it

ij> insert into emp values (’arun’,101);

1 row inserted/updated/deleted

ij> select * from emp;

EMPNAME |EMPNO

——————————–

arun |101

 

1 row selected

>>more on how to use Java to connect to Derby in embedded and network mode 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • description
  • Furl
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • TwitThis

Tags: