Retrieve base64 image stored as a CLOB from derby with Worklight adapter

故事扮演 提交于 2019-11-28 10:37:50

问题


I am trying to retrieve an image stored as a CLOB in a Derby DB via a Worklight SQL adapter. I would like to do something similar to what was written up here: https://www.ibm.com/developerworks/community/blogs/dhuyvett/entry/jsonstore_revisited_in_worklight_v6_part_1_the_adapter?lang=en except for the referenced article the author is using DB2. Does anyone know how I can do this in Derby? Currently when I go to retrieve the image doing a SQL Select, the string returned is

"IMAGE": "org.apache.derby.impl.jdbc.EmbedClob@2d236"

I would also consider mysql as an alternative. Thanks for any suggestions.

JT


回答1:


org.apache.derby.impl.jdbc.EmbedClob is a java.sql.Clob, so if you have the CLOB in a var, you should be able to get the data with:

var dataAsString = theClob.getSubString(1, theClob.length());  // Assumes all CLOBS are < 2G



回答2:


Thanks for all the great information. I ended up getting this working using MySQL. The Base64 encoded image was stored in a BLOB column. To retrieve the data, my adapter SELECT statement looks like this:

selectStatement = WL.Server.createSQLStatement("select  *, convert(IMAGE USING utf8) as CONVERTEDIMAGE from report");

then in my client-side code, I loop through the resultset to grab the image which I display via a Google Maps Marker in an infowindow

incidentRec.image = result.invocationResult.resultSet[i].CONVERTEDIMAGE;
 $marker.click(function() {
        $('#map_canvas').gmap('openInfoWindow', {'content': '<p> ' + incidentArray[this.id].description + '</br>' +     '<image + src="data:image/jpg;base64,'+  incidentArray[this.id].image + '"/>' + '</p>'}, this);
    });

When time permits, I can try the derby approach. Thanks again!



来源:https://stackoverflow.com/questions/19891164/retrieve-base64-image-stored-as-a-clob-from-derby-with-worklight-adapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!