Quantcast
Channel: MySQL Forums - Connector/Python
Viewing all articles
Browse latest Browse all 384

Problem with inserting data into MySQL (no replies)

$
0
0
Hi
I want to read the data of a sensor and transfer it to MySQL local host with "mysql.connector". The problem is that it reads the data as a list containing 500 data (that is, it reads 500 to 500, not one by one). This is my code:

master_data = master_task.read(number_of_samples_per_channel=500)
sql = "INSERT INTO vib_data2 (data) VALUES (%s)"
val = list(master_data, )
mycursor.executemany(sql, val)
mydb.commit()


I got this error:
"Could not process parameters: float(-0.15846696725827258), it must be of type list, tuple or dict"


I can fix the problem with this code:

for i in master_data:
sql = "INSERT INTO vib_data2 (data) VALUES (%s)"
val = (str(I),)
mycursor.execute(sql, val)
mydb.commit()


But the code execution time is very long (more than one second) and thus some of the data is lost.
Thank you for helping to correct the code

Viewing all articles
Browse latest Browse all 384

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>