Using Oracle Dialect in HSQLDB

HSQLDB supports Oracle dialect starting version 2.0 onwards. However, there is not much documentation or examples around this feature.

In this post, I will explain the usage of this feature with a simple example.

To enable SQL dialect, two steps are required:

1. Set the property "sql.syntax_ora=true" in your connection string.


String connectURL="jdbc:hsqldb:file:C:/projects/mxdb/mxStoreDb;sql.syntax_ora=true";

2. Set the below execute to execute before any SQL statements:


Below is a simple Java code which explains the usage:


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class HSQLConnect {

	static Connection conn;

	public static void main (String [] args) throws SQLException{
    	String driver="org.hsqldb.jdbcDriver";
    	String connectURL="jdbc:hsqldb:file:C:/projects/mxdb/mxStoreDb;sql.syntax_ora=true";

    	String username="sa";
    	String password="";

    	try {

    		conn = DriverManager.getConnection(connectURL,username, "");

			Statement st = null;
            ResultSet rs = null;

    		st= conn.createStatement();
    		st.execute("DROP TABLE MX_NAMES");
    		st.execute("CREATE TABLE MX_NAMES(NAME VARCHAR2(35))");
    		st.execute("INSERT INTO MX_NAMES VALUES('Hello World12')");
    		st.execute("INSERT INTO MX_NAMES VALUES('Hello World31')");
    		rs= st.executeQuery("SELECT  * FROM MX_NAMES");

		} catch (Exception e) {
			System.out.println("Connection closed");

Posted in Java, Oracle, Programming | Tagged , , , | Leave a comment

GWT Designer is now free! Yippee!

This is great news for the GWT developer community. In August, Google acquired Instantiations – the company which developed GWT Designer. All the products of Instantiations have now been re-launched as free tools by Google.

For more info on GWT Designer, check out the below links:

Posted in GWT, GWT-Ext, HTML, Java | Tagged , , , , | Leave a comment

Apache POI and Open Office document formats

Apache POI from version 3.6 onwards has support for SpreadSheetML (Microsoft’s Open Office XML standard). With SpreadSheetML you can generate Excel files as XML. The XML file needs to be compliant with the OOXML schema. The file extension for “.xlsx”.

To create a Excel document using OOXML use the command:

Workbook wb = new XSSFWorkbook();

To create in binary (OLE) format, use the below constructor for creating the workbook:

Workbook wb = new HSSFWorkbook();

That’s all! All further processing is the same for both XSSF and HSSF workbook formats.

Posted in Uncategorized | Tagged , , , , , , | 2 Comments


If you can keep your head when all about you
Are losing theirs and blaming it on you;
If you can trust yourself when all men doubt you,
But make allowance for their doubting too;
If you can wait and not be tired by waiting,
Or, being lied about, don’t deal in lies,
Or, being hated, don’t give way to hating,
And yet don’t look too good, nor talk too wise;

If you can dream – and not make dreams your master;
If you can think – and not make thoughts your aim;
If you can meet with triumph and disaster
And treat those two imposters just the same;
If you can bear to hear the truth you’ve spoken
Twisted by knaves to make a trap for fools,
Or watch the things you gave your life to broken,
And stoop and build ’em up with wornout tools;

If you can make one heap of all your winnings
And risk it on one turn of pitch-and-toss,
And lose, and start again at your beginnings
And never breath a word about your loss;
If you can force your heart and nerve and sinew
To serve your turn long after they are gone,
And so hold on when there is nothing in you
Except the Will which says to them: “Hold on”;

If you can talk with crowds and keep your virtue,
Or walk with kings – nor lose the common touch;
If neither foes nor loving friends can hurt you;
If all men count with you, but none too much;
If you can fill the unforgiving minute
With sixty seconds’ worth of distance run –
Yours is the Earth and everything that’s in it,
And – which is more – you’ll be a Man my son!

~Rudyard Kipling

Posted in General | Leave a comment

Thought provoking…

A mail(fwd) that I recently received…

I wish to go back to the time,
when getting high, meant on a swing.
When drinking meant Bournvita.
When dad was the only hero.
When love was mummy’s hug.
When dad’s shoulder was the highest place on earth.
When your worst enemies were your siblings.
When the only thing that could hurt were wounded knees.
When the only things broken were toys and
When good byes meant only till tomorrow……
Now we realize, life has changed so much!!!

Posted in General, Nostalgia | Leave a comment

Go, Kiss the World

Reproduced below, is an amazing speech by Subroto Bagchi, COO, MindTree Consulting India on the guiding principles of his life. Really inspiring and very touching. A tad lengthy, but worth the read.

I delivered this speech to the Class of 2006 at the IIM, Bangalore on defining success. This was the first time I shared the guiding principles of my life with young professionals.

I was the last child of a small-time government servant, in a family of five brothers. My earliest memory of my father is as that of a District Employment Officer in Koraput, Orissa. It was and remains as back of beyond as you can imagine. There was no electricity; no primary school nearby and water did not flow out of a tap. As a result, I did not go to school until the age of eight; I was home-schooled. My father used to get transferred every year. The family belongings fit into the back of a jeep – so the family moved from place to place and, without any trouble, my Mother would set up an establishment and get us going. Raised by a widow who had come as a refugee from the then East Bengal, she was a matriculate when she married my Father. My parents set the foundation of my life and the value system which makes me what I am today and largely defines what success means to me today.

As District Employment Officer, my father was given a jeep by the government. There was no garage in the Office, so the jeep was parked in our house. My father refused to use it to commute to the office. He told us that the jeep is an expensive resource given by the government – he reiterated to us that it was not ‘his jeep’ but the government’s jeep. Insisting that he would use it only to tour the interiors, he would walk to his office on normal days. He also made sure that we never sat in the government jeep – we could sit in it only when it was stationary. That was our early childhood lesson in governance – a lesson that corporate managers learn the hard way, some never do.

The driver of the jeep was treated with respect due to any other member of my Father’s office. As small children, we were taught not to call him by his name. We had to use the suffix ‘dada’ whenever we were to refer to him in public or private. When I grew up to own a car and a driver by the name of Raju was appointed – I repeated the lesson to my two small daughters. They have, as a result, grown up to call Raju, ‘Raju Uncle’ – very different from many of their friends who refer to their family drivers as ‘my driver’. When I hear that term from a school- or college-going person, I cringe. To me, the lesson was significant – you treat small people with more respect than how you treat big people. It is more important to respect your subordinates than your superiors.

Our day used to start with the family huddling around my Mother’s chulha – an earthen fire place she would build at each place of posting where she would cook for the family. There was no gas, nor electrical stoves. The morning routine started with tea. As the brew was served, Father would ask us to read aloud the editorial page of The Statesman’s ‘muffosil’ edition – delivered one day late. We did not understand much of what we were reading. But the ritual was meant for us to know that the world was larger than Koraput district and the English I speak today, despite having studied in an Oriya medium school, has to do with that routine. After reading the newspaper aloud, we were told to fold it neatly. Father taught us a simple lesson. He used to say, “You should leave your newspaper and your toilet, the way you expect to find it”. That lesson was about showing consideration to others. Business begins and ends with that simple precept.

Being small children, we were always enamored with advertisements in the newspaper for transistor radios – we did not have one. We saw other people having radios in their homes and each time there was an advertisement of Philips, Murphy or Bush radios, we would ask Father when we could get one. Each time, my Father would reply that we did not need one because he already had five radios – alluding to his five sons. We also did not have a house of our own and would occasionally ask Father as to when, like others, we would live in our own house. He would give a similar reply, “We do not need a house of our own. I already own five houses”. His replies did not gladden our hearts in that instant. Nonetheless, we learnt that it is important not to measure personal success and sense of well being through material possessions.

Government houses seldom came with fences. Mother and I collected twigs and built a small fence. After lunch, my Mother would never sleep. She would take her kitchen utensils and with those she and I would dig the rocky, white ant infested surrounding. We planted flowering bushes. The white ants destroyed them. My mother brought ash from her chulha and mixed it in the earth and we planted the seedlings all over again. This time, they bloomed. At that time, my father’s transfer order came. A few neighbors told my mother why she was taking so much pain to beautify a government house, why she was planting seeds that would only benefit the next occupant. My mother replied that it did not matter to her that she would not see the flowers in full bloom. She said, “I have to create a bloom in a desert and whenever I am given a new place, I must leave it more beautiful than what I had inherited”. That was my first lesson in success. It is not about what you create for yourself, it is what you leave behind that defines success.
My mother began developing a cataract in her eyes when I was very small. At that time, the eldest among my brothers got a teaching job at the University in Bhubaneswar and had to prepare for the civil services examination. So, it was decided that my Mother would move to cook for him and, as her appendage, I had to move too. For the first time in my life, I saw electricity in homes and water coming out of a tap. It was around 1965 and the country was going to war with Pakistan. My mother was having problems reading and in any case, being Bengali, she did not know the Oriya script. So, in addition to my daily chores, my job was to read her the local newspaper – end to end. That created in me a sense of connectedness with a larger world. I began taking interest in many different things. While reading out news about the war, I felt that I was fighting the war myself. She and I discussed the daily news and built a bond with the larger universe. In it, we became part of a larger reality. Till date, I measure my success in terms of that sense of larger connectedness.

Meanwhile, the war raged and India was fighting on both fronts. Lal Bahadur Shastri, the then Prime Minster, coined the term “Jai Jawan, Jai Kishan” and galvanized the nation in to patriotic fervor. Other than reading out the newspaper to my mother, I had no clue about how I could be part of the action. So, after reading her the newspaper, every day I would land up near the University’s water tank, which served the community. I would spend hours under it, imagining that there could be spies who would come to poison the water and I had to watch for them. I would daydream about catching one and how the next day, I would be featured in the newspaper. Unfortunately for me, the spies at war ignored the sleepy town of Bhubaneswar and I never got a chance to catch one in action. Yet, that act unlocked my imagination. Imagination is everything. If we can imagine a future, we can create it, if we can create that future, others will live in it. That is the essence of success.

Over the next few years, my mother’s eyesight dimmed but in me she created a larger vision, a vision with which I continue to see the world and, I sense, through my eyes, she was seeing too. As the next few years unfolded, her vision deteriorated and she was operated for cataract. I remember when she returned after her operation and she saw my face clearly for the first time, she was astonished. She said, “Oh my God, I did not know you were so fair”. I remain mighty pleased with that adulation even till date. Within weeks of getting her sight back, she developed a corneal ulcer and, overnight, became blind in both eyes.

That was 1969. She died in 2002. In all those 32 years of living with blindness, she never complained about her fate even once. Curious to know what she saw with blind eyes, I asked her once if she sees darkness. She replied, “No, I do not see darkness. I only see light even with my eyes closed”. Until she was eighty years of age, she did her morning yoga every day, swept her own room and washed her own clothes. To me, success is about the sense of independence; it is about not seeing the world but seeing the light.
Over the many intervening years, I grew up, studied, joined the industry and began to carve my life’s own journey. I began my life as a clerk in a government office, went on to become a Management Trainee with the DCM group and eventually found my life’s calling with the IT industry when fourth generation computers came to India in 1981. Life took me places – I worked with outstanding people, challenging assignments and traveled all over the world. In 1992, while I was posted in the US, I learnt that my father, living a retired life with my eldest brother, had suffered a third degree burn injury and was admitted in the Safderjung Hospital in Delhi. I flew back to attend to him – he remained for a few days in critical stage, bandaged from neck to toe. The Safderjung Hospital is a cockroach infested, dirty, inhuman place. The overworked, under-resourced sisters in the burn ward are both victims and perpetrators of dehumanized life at its worst. One morning, while attending to my Father, I realized that the blood bottle was empty and fearing that air would go into his vein, I asked the attending nurse to change it. She bluntly told me to do it myself. In that horrible theater of death, I was in pain and frustration and anger. Finally when she relented and came, my Father opened his eyes and murmured to her, “Why have you not gone home yet?” Here was a man on his deathbed but more concerned about the overworked nurse than his own state. I was stunned at his stoic self. There I learnt that there is no limit to how concerned you can be for another human being and what is the limit of inclusion that you can create. My father died the next day.

He was a man whose success was defined by his principles, his frugality, his universalism and his sense of inclusion. Above all, he taught me that success is your ability to rise above your discomfort, whatever may be your current state. You can, if you want, raise your consciousness above your immediate surroundings. Success is not about building material comforts – the transistor that he never could buy or the house that he never owned. His success was about the legacy he left, the mimetic continuity of his ideals that grew beyond the smallness of an ill-paid, unrecognized government servant’s world.

My father was a fervent believer in the British Raj. He sincerely doubted the capability of the post-independence Indian political parties to govern the country. To him, the lowering of the Union Jack was a sad event. My Mother was the exact opposite. When Subhash Bose quit the Indian National Congress and came to Dacca, my mother, then a schoolgirl, garlanded him. She learnt to spin khadi and joined an underground movement that trained her in using daggers and swords. Consequently, our household saw diversity in the political outlook of the two. On major issues concerning the world, the Old Man and the Old Lady had differing opinions. In them, we learnt the power of disagreements, of dialogue and the essence of living with diversity in thinking. Success is not about the ability to create a definitive dogmatic end state; it is about the unfolding of thought processes, of dialogue and continuum.

Two years back, at the age of eighty-two, Mother had a paralytic stroke and was lying in a government hospital in Bhubaneswar. I flew down from the US where I was serving my second stint, to see her. I spent two weeks with her in the hospital as she remained in a paralytic state. She was neither getting better nor moving on. Eventually I had to return to work. While leaving her behind, I kissed her face. In that paralytic state and a garbled voice, she said, “Why are you kissing me, go kiss the world.” Her river was nearing its journey, at the confluence of life and death, this woman who came to India as a refugee, raised by a widowed Mother, no more educated than high school, married to an anonymous government servant whose last salary was Rupees Three Hundred, robbed of her eyesight by fate and crowned by adversity – was telling me to go and kiss the world!

Success to me is about Vision. It is the ability to rise above the immediacy of pain. It is about imagination. It is about sensitivity to small people. It is about building inclusion. It is about connectedness to a larger world existence. It is about personal tenacity. It is about giving back more to life than you take out of it. It is about creating extra-ordinary success with ordinary lives.

Thank you very much; I wish you good luck and Godspeed. Go, kiss the world.

Posted in General | Leave a comment

GWT Quick Tip: How to check whether a GWT application is running in Hosted Mode

Sometimes, at runtime, you need to detect whether the application is running in Hosted Mode or not. E.g. you might decide to enable client side logging using GWT-Log only when the application is executing in Hosted Mode. The logging should be disabled once the application is deployed.

To check whether the application is executing in Hosted Mode, use the below API:

boolean isExecutingInHostedMode = GWT.isScript();
Posted in GWT, GWT-Ext | Tagged , , , | Leave a comment

Java Design Patterns – A Short Writeup

A design pattern is a general, language-independent technique used to solve a class of related problems. A design pattern is a widely accepted solution to a recurring design problem. It is a guideline rather than a specific solution.

An idiom, by contrast, is a low-level pattern that is specific to a programming language.

There are three basic classification of patterns: Creational, Structural and Behavioural.

Creational Patterns
Creational patterns provide/deal with different mechanisms for creation of objects. Creational patterns create the objects for you, rather than you having to instantiate them yourselves. This gives your program more flexibility in deciding which objects need to be created for a given case.

Structural Patterns
Structural Patterns describe how to compose objects and classes to form structures. They are broadly classified as object patterns and class patterns. Class patterns describe relationships with the help of inheritance. Object patterns describe how objects can be composed to form larger structures.

Behavioural Patterns
Behavioural patterns describe various means of communication between collaborating objects in the system. This ensures that the objects are loosely coupled thus avoiding hard-coding and dependencies. They also define how the flow is controlled in a complex application.

Posted in Java | Tagged | Leave a comment

Number of Days Since 1900

Here is a simple Orace query to calculate the number of days since 1900.

select to_char(sysdate,'J') - to_char(to_date('01/01/1900','DD/MM/YYYY'),'J') from dual;

Thanks to Ari Kaplan for the query!

Posted in Oracle | Tagged , | 2 Comments

Get the Last Day of The Month in Java

Use the getActualMaximum(int field) method of the Calendar class to retrieve the last day of the month.

See the below code for usage details. The code retrieves the last date for Feb 2009 as an example. You can modify the code to accept any valid date.

import java.util.Calendar;

public class GetLastDayOfMonth {
	public static void main(String[] args) {
		// Setup a Calendar instance.
		Calendar cal = Calendar.getInstance();
		// Set the year as 2009
		cal.set(Calendar.YEAR, 2009);
		// Set the month as February (can be set as 1 or Calendar.FEBRUARY)
		cal.set(Calendar.MONTH, 1);
		// Set the date as 1st - optional
		cal.set(Calendar.DATE, 1);
		System.out.println("Input date: " + cal.getTime());
		int lastDateOfMonth = cal.getActualMaximum(Calendar.DATE);
		cal.set(Calendar.DATE, lastDateOfMonth);
		System.out.println("Output Date: " + cal.getTime());
Posted in Java | Tagged , , | 1 Comment