torek, 21. avgust 2007

DB2 and string functions

If you have ever worked with DB2 and Unicode database, you must have stumbled across this problem:
If you are using characters that are not in ascii table, but nation specific ones, like đšžćč in my case, then function like LENGTH, SUBSTR, ... are not working right. Especially with JCC DB2 driver.
Example:
ResultSet rs = stmt.executeQuery("SELECT SUBSTR(NAME, 1, 10) AS NAME FROM TABLE1")
and then the tenth character is one of đšžćč(for example) then calling
rs.getstring("NAME") will give you an Exception.
There are three solutions:
- use APP/NET driver, so you at least don't get the exception
- do a substring in Java code
- use VARGRAPHIC like SELECT SUBSTR(VARGRAPHIC(NAME), 1, 10) AS NAME FROM TABLE1

At least I hope DB2 developers will fix this soon. Sometimes it really gets on my nerves.

Ni komentarjev: