Android Question [SOLVED] JDBC error when connection success

makis_best

Well-Known Member
Licensed User
Longtime User
Hello to all of you.
I finish a project using JDBC connection working just fine. (B4A.... The best....)
Yesterday I start a new project using again JDBC connection.
I did something simple... I copy from my previous project the class I had for JDBC connection.
I make some changes... everything was good since I debug my project for the first time.
The Connect sub return Success as true but the wait command not recognize it.
All the code is inside a class cold SyncClass

I post my code here cuz I need your help so I can find out what I do wrong.

B4X:
Sub Connect As ResumableSub
    RemoteSQL.InitializeAsync("RemoteSQL", driver, jdbcUrl, Username, Password)
    Wait For RemoteSQL_Ready (Success As Boolean)
    If Success = False Then
        Log("Check unfiltered logs for JDBC errors.")
    End If
    Log("Connect is " & Success)
    Return Success
End Sub

Sub CloseConnection
    RemoteSQL.Close
End Sub

Sub ListItems_Update_Local_Check(Parent As CircularProgressBar)
    Dim SQlScript As String
    SQlScript = $"SELECT Code, TS FROM LOCAL_IItem"$
    'Log(SQlScript)
    Dim Curs1 As Cursor
    Starter.LocalSQL.Initialize(File.DirRootExternal & "/DroidViewDB/", "DVD_Database.db", True)
    Curs1 = Starter.LocalSQL.ExecQuery(SQlScript)
    Main.G1.RowCounted = Curs1.RowCount
    For i = 0 To Curs1.RowCount - 1
        Curs1.Position = i
        ListItems_Update(Curs1.GetString("Code"), Curs1.GetString("TS"), Parent, i, Curs1.RowCount)
        Sleep(0)
    Next
End Sub


Sub ListItems_Update(Code1 As String, TS1 As String, Parent1 As CircularProgressBar, ii As Int, T1 As Int) As ResumableSub
    Parent1.Value = ii / T1
    Wait For (Connect) Complete (Success As Boolean)
    Log("It is :" & Success)
    If Success Then
        Try
            Dim Qry As String
            Qry = $"SELECT Code, Description FROM tem where Type in (0,12) And Code = '${Code1}' And Class = 1 TS <> '${TS1}'"$
            Dim sf As Object = RemoteSQL.ExecQueryAsync("RemoteSQL", Qry, Null)
            Wait For (sf) RemoteSQL_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
            If Success Then
                Dim i1 As Int = 1
                Do While Crsr.NextRow
                    Starter.LocalSQL.ExecNonQuery2($"Update LOCAL_ESFIItem Set Code = ?, Description= ?    WHERE Code = '${Code1}' AND TS <> '${TS1}'"$, _
                    Array As Object(Crsr.GetString("Code1"), Crsr.GetString("Description")))
                    i1 = i1 + 1
                    Sleep(0)
                Loop
                Crsr.Close
            End If
        Catch
            Success = False
            Log(LastException)
        End Try
        CloseConnection
    End If
    Return Success
End Sub
 

makis_best

Well-Known Member
Licensed User
Longtime User
What exactly does it mean? Where is the error message?

Where is the call to Connect?

I don't get any error message.
For start I call the Sub ListItems_Update_Local_Check.
Inside loop I call the Sub ListItems_Update where is connect
B4X:
Wait For (Connect) Complete (Success As Boolean)
The
B4X:
Return Success
of connect sub is always is true but Wait doesn't recognize it and exit sub.
So I don't get any error.
That's my problem.
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
I try as you say to use Wait For but when Wait For is executed
the "Success As Boolean" take the value "Error evaluating expression" and exit
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Starter.LocalSQL.ExecNonQuery2($"Update LOCAL_ESFIItem Set Code = ?, Description= ? WHERE Code = '${Code1}' AND TS <> '${TS1}'"$, _
Array As Object(Crsr.GetString("Code1"), Crsr.GetString("Description")))

there are two questionmarks where i would expect 4
Additionally i dont see where you set the values for Code1 and TS1
Asuming they do exist....

something like
B4X:
Starter.LocalSQL.ExecNonQuery2("Update LOCAL_ESFIItem Set Code = ?, Description= ? WHERE Code = ? AND TS <> ?;"$, _
                    Array As Object(Crsr.GetString("Code1"), Crsr.GetString("Description"), Code1, TS1))
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
@DonManfred
Values do exist....
The problem is not about the syntax of ExecNonQuery2
The problem is that application never execute the command cuz Wait For fails.

To be exact I get false on success here.

B4X:
Dim sf As Object = RemoteSQL.ExecQueryAsync("RemoteSQL", Qry, Null)
            Wait For (sf) RemoteSQL_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
            If Success Then
                Dim i1 As Int = 1
                Do While Crsr.NextRow
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…