Tuesday, August 9, 2011

JBoss error : Expecting "jsp:param" standard action with "name" and "value" attributes

While migration of code from WebSphere to JBoss below mentioned error was observed.

Expecting "jsp:param" standard action with "name" and "value" attributes

Solution :

Replace old code

<jsp:include flush="true" page="file.jsp">
</jsp:include>
 OR
<jsp:forward page="file.jsp">
</jsp:forward>


With new code

<jsp:include flush="true" page="file.jsp"/>
OR
<jsp:forward page="file.jsp"/>




Monday, August 8, 2011

DB2 : the syntax of the string representation of a datetime value is incorrect

DB2 query to get data between two DATE range ie to get data between start date and end date. Basically comparism of dates in DB2.

while writing a SQL query i was getting below mentioned error.


the syntax of the string representation of a datetime value is incorrect

Correct Syntax : 
select OPRID,DATETIME_STAMP,H_SS_ID from Q.PROJECT where date(DATETIME_STAMP) between '2011-08-04' and '2011-08-06' order by DATETIME_STAMP

here it will get data from date range between  2011-08-04 and 2011-08-06. Note date syntax (YYYY-MM-DD)

Also note the date function DATE(..) it will convert complete date to a YYYY-MM-DD format.

 If you want data of one particular day

select OPRID,DATETIME_STAMP,H_SS_ID from Q.PROJECT where date(DATETIME_STAMP) = '2011-08-04'

The basics of DATE TIME in DB2

To get the current date, time, and timestamp using SQL, reference the appropriate DB2 registers:

SELECT current date FROM sysibm.sysdummy1 
SELECT current time FROM sysibm.sysdummy1 
SELECT current timestamp FROM sysibm.sysdummy1 
 
The sysibm.sysdummy1 table is a special in-memory table that can be used to discover the value of DB2 registers. 
Given a date, time, or timestamp, you can extract (where applicable) the year, month, day, hour, minutes, seconds, and microseconds portions independently using the appropriate function:

YEAR (current timestamp) 
MONTH (current timestamp) 
DAY (current timestamp) 
HOUR (current timestamp) 
MINUTE (current timestamp) 
SECOND (current timestamp) 
MICROSECOND (current timestamp) 


Extracting the date and time independently from a timestamp is also very easy:

DATE (current timestamp) 
TIME (current timestamp) 
 
 
You can also perform date and time calculations using, for lack of a better term, English: 
 
current date + 1 YEAR 
current date + 3 YEARS + 2 MONTHS + 15 DAYS 
current time + 5 HOURS - 3 MINUTES + 10 SECONDS 
 
To calculate how many days there are between two dates, you can subtract dates as in the following:
 
days (current date) - days (date('1999-10-22')) 
 

Sunday, August 7, 2011

Java : Strings Are Immutable Objects


Strings Are Immutable Objects

In Java, each character in a string is a 16-bit Unicode character.

In Java, strings are objects. Just like other objects, you can create an instance of a String with the new keyword, as follows:

String s = new String();

This line of code creates a new object of class String, and assigns it to the reference variable s. So far, String objects seem just like other objects. Now, let's give the String a value:

s = "abc";


The String class has many constructors, so you can use a more efficient shortcut. Please see String API.

String s = new String("abc");


And just because you'll use strings all the time, you can even say this:

String s = "abc";

There are some subtle differences between these options that we'll discuss later, but what they have in common is that they all create a new String object, with a value of "abc", and assign it to a reference variable s. Now let's say that you want a second reference to the String object referred to by s:


String s2 = s; // refer s2 to the same String as s



So far so good. String objects seem to be behaving just like other objects, so what's all the fuss about?…Immutability!
Once you have assigned a String a value, that value can never change - it's immutable.



The good news is that while the String object is immutable, its reference variable is not, so to continue with our previous example:

s = s.concat("def"); // the concat() method 'appends'
                            // a literal to the end






The VM took the value of String s (which was "abc"), and tacked "def" onto the end, giving us the value "abcdef". Since Strings are immutable, the VM couldn't stuff this new value into the old String referenced by s, so it created a new String object, gave it the value "abcdef", and made s refer to it. At this point in our example, we have two String objects: the first one we created, with the value "abc", and the second one with the value "abcdef". Technically there are now three String objects, because the literal argument to concat, "def", is itself a new String object. But we have references only to "abc" (referenced by s2) and "abcdef" (referenced by s).

Important Facts About Strings and Memory



To make Java more memory efficient, the JVM sets aside a special area of memory called the "String constant pool." When the compiler encounters a String literal, it checks the pool to see if an identical String already exists. If a match is found, the reference to the new literal is directed to the existing String, and no new String literal object is created. (The existing String simply has an additional reference.) Now we can start to see why making String objects immutable is such a good idea. If several reference variables refer to the same String without even knowing it, it would be very bad if any of them could change the String's value.


You might say, "Well that's all well and good, but what if someone overrides the String class functionality; couldn't that cause problems in the pool?" That's one of the main reasons that the String class is marked final. Nobody can override the behaviors of any of the String methods, so you can rest assured that the String objects you are counting on to be immutable will, in fact, be immutable.


Now let's assume that no other String objects exist in the pool:


String s = "abc"; // creates one String object and one
                        // reference variable
In this simple case, "abc" will go in the pool and s will refer to it.


String s = new String("abc"); // creates two objects,
                                         // and one reference variable


In this case, because we used the new keyword, Java will create a new String object in normal (non-pool) memory, and s will refer to it. In addition, the literal "abc" will be placed in the pool.



The StringBuffer and StringBuilder Classes



The java.lang.StringBuffer and java.lang.StringBuilder classes should be used when you have to make a lot of modifications to strings of characters. String objects are immutable however objects of type StringBuffer and StringBuilder can be modified over and over again without leaving behind a great effluence of discarded String objects.


StringBuffer vs. StringBuilder


The StringBuilder class was added in Java 5. It has exactly the same API as the StringBuffer class, except StringBuilder is not thread safe. In other words, its methods are not synchronized hence StringBuilder is faster than  StringBuffer.




Tuesday, April 19, 2011

AQT : Processing error at sql_setvars


After installing AQT in my PC I was not able to run it. After login to DB2 server whenever I used to press SQL to open an SQL window, I used to get below mentioned error. 



Error :
  
Processing error at sql_setvars
Component 'TABCTL32.OCX' or one of its dependencies not correctly registered: a file is missing or invalid

What I did is I downloaded the file TABCTL32.OCX from the below mentioned URL



And added the file TABCTL32.OCX to the path C:\WINXP\system32\TABCTL32.OCX

and run the bat file C:\Program Files\Advanced Query Tool\ocx_register_v8.bat

and after restarting AQT, it was working fine. I wanted to share this issue with you If anyone else faced this kind of similar issue, hope it may helped you.

Friday, April 15, 2011

Java : Methods with Variable Argument Lists (var-args)

Methods with Variable Argument Lists (var-args)

As of 5.0, Java allows you to create methods that can take a variable number of arguments. Depending on where you look, you might hear this capability referred to as "variable-length argument lists," "variable arguments," "var-args," "varargs, "variable arity parameter". They're all the same thing.

As a bit of background,to use the terms "argument" and "parameter".

arguments The things you specify between the parentheses when you'reinvoking a method:

doStuff("a", 2);   // invoking doStuff, so a & 2 are arguments

parameters The things in the method's signature that indicate what the method must receive when it's invoked:

void doStuff(String s, int a) { } // we're expecting two
                                            // parameters: String and int

The declaration rules for var-args:

Var-arg type When you declare a var-arg parameter, you must specify the type of the argument(s) this parameter of your method can receive. (This can be a primitive type or an object type.)

Basic syntax To declare a method using a var-arg parameter, you follow the type with an ellipsis (...), a space, and then the name of the array that will hold the parameters received.

Other parameters It's legal to have other parameters in a method that uses a var-arg.

Var-args limits The var-arg must be the last parameter in the method's signature, and you can have only one var-arg in a method.

Let's look at some legal and illegal var-arg declarations:

Legal:
void doStuff(int... x) { }  // expects from 0 to many ints
                                    // as parameters
void doStuff2(char c, int... x) { }  // expects first a char,
                                                 // then 0 to many ints
void doStuff3(Animal... animal) { }  // 0 to many Animals

Illegal:
void doStuff4(int x...) { } // bad syntax
void doStuff5(int... x, char... y) { } // too many var-args
void doStuff6(String... s, byte b) { } // var-arg must be last

Conclusion 

As of Java 5, methods can declare a parameter that accepts from zero to many arguments, a so-called var-arg method.

A var-arg parameter is declared with the syntax type... name; 

for instance: 
doStuff(int... x) { }

A var-arg method can have only one var-arg parameter.

In methods with normal parameters and a var-arg, the var-arg must come last.