Android Question [Solved]How can I update the records in multiple JRDC2 fields?

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
I need to update several fields at the same time with a single query.
This is the code I have in the JRDC server file 'config.properties'.
upload_2018-8-8_19-25-40.png


And this is the code in B4A client.
B4X:
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("update_base_table", Array (col1,col2,col3,col4,col5,col6,col7,col8,col9,col10))
    Dim j As HttpJob = CreateRequest.ExecuteBatch(Array(cmd), Null)
    Wait For (req.ExecuteCommand(cmd,Null)) JobDone(j As HttpJob)
    If j.Success Then
        Log("Update successfully!")
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release

If there is a way to execute the command in SQL, I would appreciate it, because this way it does not work

Thank you.
 
Last edited:

OliverA

Expert
Licensed User
Longtime User
1) Why does "this way" not work? Any error messages?
2) I think your missing a parameter (specific to your case) when you are using CreateCommand. You're passing all the columns (col1..col10), but you are not passing a parameter for the id = ? part.
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
1) Why does "this way" not work? Any error messages?
2) I think your missing a parameter (specific to your case) when you are using CreateCommand. You're passing all the columns (col1..col10), but you are not passing a parameter for the id = ? part.
I already did it but it still does not work.
This way it seems to work, but it has a problem when it comes to updating the fields since it makes them in disarray.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
the table loses order.
What are you trying to say here? Are you using an ORDER BY clause to sort your displayed data? If not, why would you think a SELECT statement is obligated to return any order at all?
The variable 'col1' is the id.
The 'id' in the table is an 'id INTEGER PRIMARY KEY AUTO_INCREMENT'
Why don't you post the full structure of the table (since I can't seem to make sense of the statements).
I already did it but it still does not work
Why don't you show us the "fixed" code that you are using (since the one you supplied in post#1 is incorrect as posted).
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
What are you trying to say here? Are you using an ORDER BY clause to sort your displayed data? If not, why would you think a SELECT statement is obligated to return any order at all?
I want to say that when updating a specific field, another ends up being updated.
Why don't you show us the "fixed" code that you are using (since the one you supplied in post#1 is incorrect as posted).
that is all the code.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
This is the table
Then both your config.properties and your client code is wrong (since the config.properties is wrong). BTW, next time post text instead of images (easier to copy/paste/quote).

Config.properties
B4X:
sql.update_base_table=UPDATE Table1 SET col2 = ?,\
   col3 = ?,\
   col4 = ?,\
   col5 = ?,\
   col6 = ?,\
   col7 = ?,\
   col8 = ?,\
   col9 = ?,\
   col10 = ? WHERE id = ?

Client code correction
B4X:
Dim cmd As DBCommand = CreateCommand("update_base_table", Array (col2,col3,col4,col5,col6,col7,col8,col9,col10,col1))
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Then both your config.properties and your client code is wrong (since the config.properties is wrong). BTW, next time post text instead of images (easier to copy/paste/quote).

Config.properties
B4X:
sql.update_base_table=UPDATE Table1 SET col2 = ?,\
   col3 = ?,\
   col4 = ?,\
   col5 = ?,\
   col6 = ?,\
   col7 = ?,\
   col8 = ?,\
   col9 = ?,\
   col10 = ? WHERE id = ?

Client code correction
B4X:
Dim cmd As DBCommand = CreateCommand("update_base_table", Array (col2,col3,col4,col5,col6,col7,col8,col9,col10,col1))
Okay. I try it and I warn you. Okay thanks
 
Upvote 0
Top