I need to make a database call to pull CLOB data. The data that I’m getting back seems to be a java CLOB object.
I’m trying to retrieve the data with the following code in my template:
#set($len = $pictures.length())
#set($chrome_default_img = $pictures.getSubString(1,$len))
But the getSubString method doesn’t seem to like a velocity var passed in…
I can get this to work by passing the actual length as follows
#set($chrome_default_img = $pictures.getSubString(1,4499))
Any suggestions?
Thanks,
Veeren
dbenua
2
Clob.length() returns a long, and String.subString() wants an int.
Try something like $len.intValue().
If that doesn’t work, try $tools.math.toInteger($len).intValue()
Dave
dbenua
4
Could you post your code so that others may learn?
Dave
Here’s the code. It shows how to use the $rx.db.get() function and pull data from a CLOB object, which is in blue below.
...
#else
##get the model id and trim description
#set($select = 'model_id, style, pictures')
#set($from ='model_info_re t')
#set($where ="t.style_id = $style_id")
#set($sql = "select $select from $from where $where")
#set($results = $rx.db.get($db,$sql))
#set($model_id = $results.get(0).get('MODEL_ID'))
#set($style = $results.get(0).get('STYLE'))
#end
##set pictures from results set
#set($pictures = $results.get(0).get('PICTURES') )
##if null then set to empty string
#if(!$pictures)
#set($chrome_default_img = '')
#else
[B] #set($len = $pictures.length())
#set($chrome_default_img = $pictures.getSubString(1,$len.intValue()))[/B]
#end
...