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

后端 未结 2 1289
感情败类
感情败类 2020-12-22 05:51

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.

相关标签:
2条回答
  • 2020-12-22 06:08

    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
    
    0 讨论(0)
  • 2020-12-22 06:11

    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!

    0 讨论(0)
提交回复
热议问题