B4J Question how to pass a database information at array for including in my app

juangtju

Member
Hello friends of the forum, I need help in this dilemma that I have, the detail is that after making the connection and verifying that if it works, that is, it brings me the data, I do not know how to present it in an array, or better save it in a document to parse the information and put it as a list to choose, that's the detail. ,

This is the same example that erel published about the creation of b4xtables and forms that to fill them uses a json file to create the list but I don't know how to send the list from the database so that it works
 

Attachments

  • imagen_2021-11-01_143754.png
    imagen_2021-11-01_143754.png
    165.1 KB · Views: 176

drgottjr

Expert
Licensed User
Longtime User
what do you mean by "brings me the data"?
can you show exactly how you ask for the data
and exactly how the server "brings" it to you?
and can you show an exact, small sample of
what the data looks like when you receive it?

normally when you receive a response from
a server, you can do what you like with it (eg,
create an array, a list, a file, etc).
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Check this example:
 
Upvote 0

juangtju

Member
Sorry for writing late, but what I want to do is that this form that I open when the tables are created, the information instead of coming from a text file that is as it comes from the factory, I read the options as a list of string and so I can choose the ones I need, that's what I'm looking for
 
Upvote 0

juangtju

Member
Check this example:
thats is a example thats i working on, but the problem is i could not put a query for search results for call of a database (mysql) to a list for that form
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
i could not put a query for search results for call of a database (mysql)
So, maybe this is the example you need?


In this case, the database is a sqlite, but if you connect to a mysql database, the process is the same.
 
Upvote 0

juangtju

Member
So, maybe this is the example you need?


In this case, the database is a sqlite, but if you connect to a mysql database, the process is the same.
that is i really need , with this information i continue my app, thanks.
 
Upvote 0

juangtju

Member
I don’t understand your question.
You need to understand different examples how they work and combine them to form the answer.
right its true , i continue searching for i want in the app, thanks , if i have a better question i put in that thread
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Maybe these posts can help you to complete the puzzle:



Then, you can use them to populate the B4XTable instead a xCLV.
 
Upvote 0

juangtju

Member
Hello, thanks for answering friend, yes, today I downloaded your example that way, although I was testing with the direct connection to mysql and if the information calls me but I don't know how to transform it into a string type list so that the form made in json format, I have tried but with no result
 

Attachments

  • imagen_2021-11-04_094140.png
    imagen_2021-11-04_094140.png
    114.9 KB · Views: 130
  • imagen_2021-11-04_094211.png
    imagen_2021-11-04_094211.png
    169.4 KB · Views: 143
  • imagen_2021-11-04_094300.png
    imagen_2021-11-04_094300.png
    173.1 KB · Views: 142
Upvote 0

juangtju

Member
As in the previous images you can see that I can create the connection without problems, but I want it to read the json options instead of the text file it creates, read them from the database but I have not found the solution
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
As in the previous images you can see that I can create the connection without problems, but I want it to read the json options instead of the text file it creates, read them from the database but I have not found the solution
As suggested by Jose, you can use jRDC2.
jRDC2 doesn't work with JSON by default. The client app uses DBRequestManager class to read the data.
You can then assign the object into column array and pass to a list for B4XTable.
See the log from the following sub and you will found the values of the data return from your database query or table.

B4X:
'Prints the table to the logs.
Public Sub PrintTable(Table As DBResult)
    Log("Tag: " & Table.Tag & ", Columns: " & Table.Columns.Size & ", Rows: " & Table.Rows.Size)
    Dim sb As StringBuilder
    sb.Initialize
    For Each col In Table.Columns.Keys
        sb.Append(col).Append(TAB)
    Next
    Log(sb.ToString)
    For Each row() As Object In Table.Rows
        Dim sb As StringBuilder
        sb.Initialize
        For Each record As Object In row
            sb.Append(record).Append(TAB)
        Next
        Log(sb.ToString)
    Next
End Sub

If you want to use JSON, then you can check out some of my examples.
Reason to use JSON is I can use it in web app. If you just work with B4J/B4A/B4i then jRDC2 can do the job. It is much simpler.
 
Upvote 0

juangtju

Member
hello again, i'm working on jose aguilar's example with jrdc2 but i can't understand how it works, i find it more difficult to understand this type of process, nevertheless i'm looking for the solution, thank you all anyway
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Here is an example.

For config.properties, you need to add some new SQL commands:
B4X:
#sql.insert_animal=INSERT INTO animals VALUES (null, ?,?)
sql.insert_animal=INSERT INTO animals (name, image) VALUES (?, null)
sql.select_animals=SELECT id, name, image FROM animals
 

Attachments

  • JRDC_Client.zip
    5 KB · Views: 112
Upvote 0

josejad

Expert
Licensed User
Longtime User
Upvote 0

juangtju

Member
thats greats friend , but i continue working in a app based on b4xtables and forms of erel, but i need how to convert, the strings to a list , thats really help me to much, This information from the first photo on the right in the log brings it to me from the database and I want to save it in a text document, but I don't know how to convert a string to a list to pass the data, could you help me with an example please
 

Attachments

  • imagen_2021-11-08_092113.png
    imagen_2021-11-08_092113.png
    142 KB · Views: 135
Upvote 0

josejad

Expert
Licensed User
Longtime User
Hi Juangtju:

Sorry, but I think you should start a new thread. The philosophy of the forum is that every thread should have just a question, with a descriptive subject, in order making the searches and help for other people more easy.

You've post three post everyone with differents questions.
You should post the code and logs as text (with [code] ... your code here ... [/code] tags) to make it easier to read.

Said this, if you want to save the list, you should add the rs elements to a list

B4X:
Dim l as list
list.initialize
do while rs.Nextrow
  list.add(rs.GetString(1))
loop
File.WriteList(File.DirApp, "prueba.txt", l)

Creo que deberías crear un nuevo hilo para esta pregunta, ya que la filosfía del foro es que cada hilo tenga una sola pregunta en el primer post, para hacer más fáciles las búsquedas y que puedan ser de ayuda para otros usuarios.

En este hilo ya has puesto varias preguntas sin relación unas con otras.
También deberías poner tu código y los log's como texto (encerrándolo entre etiquetas [code] ... tu código ... [/code]) para hacerlo más legible.
 
Last edited:
Upvote 0

juangtju

Member
If you are right friend, I am new to this forum and continue learning, thanks for the example and of course I will put into practice the information you have given me about the forum, thanks again
 
Upvote 0
Top