Android Question how to update db with jrdc2

K_Kai

Member
I use jrdc2-b4j connection MSSQL
But there is no update process in the example
How should i write
my db:
1610543458334.png

in config.properties:
B4X:
sql.update_app=update animals set kg=? where id=?
B4X:
My code , it has Errors
B4X:
Sub UpdateRecord(kg As String,id As Int)
Dim cmd As DBCommand = CreateCommand("update_app", Array(kg,id))
Dim j As HttpJob = CreateRequest.ExecuteBatch(Array(cmd), Null)
Wait For(j) JobDone(j As HttpJob)
If j.Success Then
Log("Inserted successfully!")
Else
Log("error:" & j.ErrorMessage)
End If
j.Release
End Sub
Sub Button2_Click
UpdateRecord(EditText3.Text,EditText1.Text )   ''Text3 is kg, text1 is id
End Sub
 

aeric

Expert
Licensed User
Longtime User
This is not easy.

Here are the steps to take note:

1. The query for MS SQL is different from MySQL

config (config.properties):
#SQL COMMANDS
sql.create_table=IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'animals'))\
CREATE TABLE animals\
(\
    id int IDENTITY(1,1) PRIMARY KEY NOT NULL,\
    animal nvarchar(50) NOT NULL,\
    kg numeric(10, 0) NULL,\
    color nvarchar(50) NULL,\
    age numeric(10, 0) NULL DEFAULT (0),\
    die_time smalldatetime NULL\
);

sql.insert_animal=INSERT INTO animals (animal, kg, color, age) VALUES (?,?,?,?)
sql.select_animals=SELECT * FROM animals WHERE id=?;
# sql.update_animals=update animals set kg=? where id=?
sql.update_animal=UPDATE animals SET animal=?, kg=?, color=?, age=? WHERE id=?
sql.update_animal_kg=UPDATE animals SET kg=? WHERE id=?

2. Take note becareful of the ? mark at the end # sql.update_animals=update animals set kg=? where id=?. Take note of typo errors like animal vs animals or select_animal vs select_app.

3. B4A Client app, please add the following into Manifest Editor to connect to http protocol
Manifest Editor:
CreateResourceFromFile(Macro, Core.NetworkClearText)

Attached is my modified Client.
 

Attachments

  • RemoteServerClient.zip
    12 KB · Views: 167
Upvote 0
Top