B4J Question [ABMaterial] get blob data and show it in ABMimage

jayel

Active Member
Licensed User
Longtime User
Hello,

I want to get BLOB images from a database and show it in a ABMimage.
I suppose, I have to save the blob as a file and then put the image in ABMImage as so :
B4X:
Sub ReadBlob(SQL As SQL,Query As String) As List
    Dim Cursor1 As ResultSet
    Dim myreturn As List
    'Using ExecQuery2 is safer as it escapes special characters automatically.
    'In this case it doesn't really matter.
    Dim dir As String = "../images/"
    Dim filename As String
    Dim machid As Int
    Dim produktid As Int
    Cursor1 = SQL.ExecQuery(Query)
    Do While Cursor1.NextRow
        machid = Cursor1.GetInt("machnr")
        produktid = Cursor1.GetInt("produktid")
        filename = machid & "_" & produktid & ".jpg"
        Dim Buffer() As Byte 'declare an empty byte array
        Buffer = Cursor1.GetBlob("afbeelding")
        Dim out As OutputStream = File.OpenOutput(dir, filename, False)
        out.WriteBytes(Buffer, 0, Buffer.Length)
        out.Close
        myreturn.Add(filename)
    Loop
'    Dim Bitmap1 As Image
'    Bitmap1.Initialize2(InputStream1)
'    InputStream1.Close
    'Activity.SetBackgroundImage(Bitmap1)
    Return myreturn
End Sub

I get following error
dec 22, 2016 2:36:14 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 20000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge0z29laqzy92wr19uf|57c10a0e, debugUnreturnedConnectionStackTraces -> false, description ->...
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.io.FileNotFoundException: ..\images\593_16694.jpg (Het systeem kan het opgegeven pad niet vinden)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$1.run(WebSocketModule.java:126)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:195)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.io.FileNotFoundException: ..\images\593_16694.jpg (Het systeem kan het opgegeven pad niet vinden)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:471)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:409)
at be.robotronic.kraanserver.kranenoverzicht._page_parseevent(kranenoverzicht.java:1924)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 10 more
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: ..\images\593_16694.jpg (Het systeem kan het opgegeven pad niet vinden)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:462)
... 17 more
Caused by: java.io.FileNotFoundException: ..\images\593_16694.jpg (Het systeem kan het opgegeven pad niet vinden)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:371)
at be.robotronic.kraanserver.dbmkranen._readblob(dbmkranen.java:360)
at be.robotronic.kraanserver.kranenoverzicht._buildtabcontainer(kranenoverzicht.java:1089)
at be.robotronic.kraanserver.kranenoverzicht._gettabs(kranenoverzicht.java:1657)
at be.robotronic.kraanserver.kranenoverzicht._connectpage(kranenoverzicht.java:1557)
at be.robotronic.kraanserver.kranenoverzicht._page_ready(kranenoverzicht.java:1956)

Is this the way I have to do it? Or are there other ways?

John
 
Top