Android Question http SQL

TILogistic

Expert
Licensed User
Longtime User
see:

 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
You want to connect to the database that contains the Android mobile application.

or

Request data via web API (Return Json) from the HTTP server of the Android mobile application.
 
Last edited:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
the client app can connect with the server device? Yes

Can we do that with JdbcSQL? No

what should the driver type and connection string be?

Only via web API returning Json data (GET and POST)

see example:


Modify Response:

Response.SendString(page)

page = Html to Data Json

B4X:
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)
    Try
        Log("Client: " & Request.RemoteAddress & ", Request: " & Request.RequestURI)
        Dim page As String = GetTemplate("template.html")
        Response.SetContentType("text/html")
        Dim query As String = Request.GetParameter("query")
   
        If query <> "" Then 'a query has been sent
            page = page.Replace("$QUERY$", query)
            Dim table As String
            Try
                table = DBUtils.ExecuteHtml(SQL, query, Null, 200, False)
            Catch
                table = LastException.Message 'There might be an error in the query.
            End Try
            page = page.Replace("$TABLE$", table)
        Else
            page = page.Replace("$QUERY$", "SELECT * FROM Students")
            page = page.Replace("$TABLE$", "")
        End If
        Response.SendString(page)
    Catch
        Response.Status = 500
        Log("Error serving request: " & LastException)
        Response.SendString("Error serving request: " & LastException)
    End Try
End Sub

Use APP client:

 
Last edited:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
read: local SQLite databases.

 
Upvote 0

catyinwong

Active Member
Licensed User
Longtime User


So the client code should be something like this for getting data from the database in the server device?


B4X:
Sub DownloadQuote
 Dim j As HttpJob j.Initialize("", Me) 'name is empty as it is no longer needed 
Dim filter as string = "select * from table"
Dim IP as string = "xxx.xxx.xxx.x"
j.Download("http://" & IP & "/wp-json/posts?" & filter) 
Wait For (j) JobDone(j As HttpJob)
 If j.Success Then 'The result is a json string. We parse it and log the fields. 
Dim jp As JSONParser jp.Initialize(j.GetString) Dim quotes As List = jp.NextArray 

For Each quot As Map In quotes Log("Title: " & quot.Get("title")) Log("Content: " & quot.Get("content")) Next
 End If 
j.Release
 End Sub
 
Upvote 0

catyinwong

Active Member
Licensed User
Longtime User
I tried the above code with the ip : 127.0.0.1 since I am trying to test the codes without any network. And it returns ResponseError. reason: java .net.connectexception: Failed to connect to /127.0.0.1:80, Reponse
 
Upvote 0

aeric

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