I am currently writing a Java program and decided to use JSON MySQL as my database. What is the correct syntax for me to insert a variable to JSON MySQL Database.
Table:
mysql> desc sales;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| sale | json | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
Java Code:
String name = "Izzat";
String place = "Cheras";
String sql = "INSERT INTO sales(id, sale) VALUES ('9','{\"Name\":"+name+",\"Place\":"+place+"}')";
I got an error:
INSERT INTO sales(id, sale) VALUES ('9','{"Nama":Izzat,"Place":"Cheras"}') Data truncation: Invalid JSON text: "Invalid value." at position 8 in value for column 'sales.sale'.
May I know what is the correct syntax for this?
Thank you in advance.