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
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
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