1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question [SOLVED] JDBC error when connection success

Discussion in 'Android Questions' started by makis_best, Jun 13, 2019.

  1. makis_best

    makis_best Active Member Licensed 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.

    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    What exactly does it mean? Where is the error message?

    Where is the call to Connect?
     
  3. makis_best

    makis_best Active Member Licensed User

    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
    Code:
    Wait For (Connect) Complete (Success As Boolean)
    The
    Code:
    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.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    This means that ListItems_Update is also a resumable sub and you should call it with Wait For as well.
     
  5. makis_best

    makis_best Active Member Licensed User

    I try as you say but now I get the error "Success - Error evaluating expression."
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    I don't see how we can help you with the information provided...
     
  7. makis_best

    makis_best Active Member Licensed 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
     
  8. DonManfred

    DonManfred Expert Licensed User

    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
    Code:
    Starter.LocalSQL.ExecNonQuery2("Update LOCAL_ESFIItem Set Code = ?, Description= ? WHERE Code = ? AND TS <> ?;"$, _
                        
    Array As Object(Crsr.GetString("Code1"), Crsr.GetString("Description"), Code1, TS1))
     
  9. makis_best

    makis_best Active Member Licensed 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.

    Code:
    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: Jun 14, 2019
  10. makis_best

    makis_best Active Member Licensed User

    I find the solution....
    The problem was on Sql Syntax

    Thank you again for your help
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice