Android Question Error Save Blob to mysql table

4rdn1_s

Member
Hi,
I'm trying to save a record that contain Blob data type but it always unsuccessful and I don't understand why,
here's my code, maybe someone can help me.

Thanks

Blob Saving Error:
    Dim Buffer() As Byte = ImageToBytes(Foto)
    
    Msgbox2Async("Save data ??","","Yes","Cancel","",Null,True)
    Wait For Msgbox_Result(Result As Int)
    If Result = DialogResponse.POSITIVE Then

        DateTime.DateFormat="yyyy-MM-dd"
        Wait For (CallSub(Starter,"Connect")) Complete (Success As Boolean)
        If Success Then
            Try
                Starter.mysql.AddNonQueryToBatch("Insert into t_dpt(no_kk,no_nik,nama,kota_lahir,tgl_lahir,status_kawin,jenis_kelamin,alamat,no_rt,no_rw,kelurahan," & _
                                                "kecamatan,kota,propinsi,no_tps,disabilitas,status_perekaman,nm_ts,cek,keterangan,aktif_partai,foto_file,dt) Values(" & _
                                                "'" & EditText7.text & "','" & EditText1.Text & "','" & EditText4.Text & "','" & nmKota & "'," & _
                                                "'" & DateTime.Date(AnotherDatePicker1.Date) & "','" & idKawin & "','" & idJkel & "','" & Starter.Remvpetik(EditText6.Text) & "'," & _
                                                "'" & EditText9.Text & "','" & EditText8.Text & "','" & nmKel & "','" & nmKec & "'," & _
                                                "'" & nmKab & "','" & nmProp & "','" & Spinner6.SelectedItem & "','" & idDisA & "'," & _
                                                "'" & idRekam & "','" & NmTS & "'," & IIf(Check1.Checked,1,0) & ",'" & Starter.Remvpetik(EditText2.Text) & "'," & _
                                                "'" & Starter.remvpetik(EditText3.Text) & "',[B]" & Buffer & "[/B],'" & DateTime.Date(DateTime.Now) & "')",Null)
                Dim RsObj As Object = Starter.mysql.ExecNonQueryBatch("Mysql")
                wait for (RsObj) Mysql_NonQueryComplete (Success As Boolean)
                If Success Then
                    MsgboxAsync("Record Saved.","Success")
                    
.....
                Else
                    Success = False
                    Log(LastException)
                    MsgboxAsync("An error occurred.","Fail")
                End If

And Here 's The Error :

(MySQLSyntaxErrorException) com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[B@68f7b30,'2022-09-21')' at line 1
 

4rdn1_s

Member
Such code should be deleted.
You need to learn how to use parameterized queries.

Good video tutorial about SQL: https://www.b4x.com/etp.html
which one Erel??

my error caused by this " & Buffer & " in Line 18, why can I insert byte into Blob ??

Bytheway still can't watch the Video got this error "Vimeography Error: There was an error fetching the embed code from Vimeo."
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Mahares

Expert
Licensed User
Longtime User
my error caused by this " & Buffer & " in Line 18, why can I insert byte into Blob ??
If you need a push, it should be something like this, using string literals and parameterized query:
B4X:
Starter.mysql.AddNonQueryToBatch($"Insert into t_dpt(no_kk,no_nik,nama,kota_lahir,tgl_lahir,
        status_kawin,jenis_kelamin,alamat,no_rt,no_rw,kelurahan,
        kecamatan,kota,propinsi,no_tps,disabilitas,status_perekaman,
        nm_ts,cek,keterangan,aktif_partai,foto_file,dt) Values(?,?,?,?,?,?,?,?,?,?,?,?,
        ?,?,?,?,?,?,?,?,?,?,?)"$, Array As Object( EditText7.text, EditText1.Text, your other variables, Buffer, DateTime.Date(DateTime.Now) ))
Make sure number of question marks matches number of fields.
 
Upvote 0
Top