Android Question B4A - insert image into database with jRDC2

Anderson Linhares

Member
Licensed User
How do I write the image from an ImageView to the database using jRDC2?
Everything works, but when I try to pass the parameter of the image it gives error.
I've tried it in many ways and nothing.
Need help!!!
 

Anderson Linhares

Member
Licensed User
Sub ImageToBytes(Img As Bitmap) As Byte()
Dim out As OutputStream
out.InitializeToBytesArray(0)
Img.WriteToStream(out,100,"PNG")
out.Close
Return out.ToBytesArray
End Sub

Sub BtnConfirma_Click

Dim bytes() As Byte = ImageToBytes(ImgMT_Imagem.Bitmap)

Dim su As StringUtils

Dim cmd1 As DBCommand = CreateCommand("insert_atendimento_ci", Array(mData_Atendimento, mHora_Atendimento, Starter.G_Cod_Atendente, mCod_Cliente, "Não", mCod_Procedimento, mValor_Procedimento, SpnMT_Tamanho_CI.SelectedItem, SpnMT_Espessura_CI.SelectedItem, SpnMT_Modelo_CI.SelectedItem, SpnMT_FAN_CI.SelectedItem,SpnMT_Quantidade_CI.SelectedItem, SpnMT_Cor_CI.SelectedItem, TxtMT_Numero_Cola_CI.Text, TxtMT_Informacao.Text, su.EncodeBase64(bytes)))

Dim j1 As HttpJob = CreateRequest.ExecuteBatch(Array(cmd1), Null)
Wait For(j1) JobDone(j1 As HttpJob)

If j1.Success Then
ToastMessageShow("Dados Confirmados !!!",False)
Else
'Log("ERROR: " & j1.ErrorMessage)
ToastMessageShow("Erro ao Gravar Dados !!!",False)
End If

j1.Release

End Sub

********************** LOG **************************************

ResponseError. Reason: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'MT_Imagem' at row 1, Response: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column &apos;MT_Imagem&apos; at row 1</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /rdc. Reason:
<pre> com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column &apos;MT_Imagem&apos; at row 1</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>
</body>
</html>
** Activity (atendimento) Pause, UserClosed = true **
** Activity (agenda) Resume **

*******************************************************************
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…