Python Forum
inserting data to mysql with python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
inserting data to mysql with python
#1
Hello,

Would anyone be able to help me out with the python code. I have been trying to write a code to read a value from .csv file and insert it into the mysql database. Unfortunately, I keep getting the error that syntax is incorrect.

This is the code I have written:
cur.execute("INSERT INTO Leashold_tb (leashold_or_not) VALUES (%(leashold_or_not,)s), ")

The error message I get is:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1

I have been looking into many guides online, but I just can not find the correct way.

Would anyone be able to help me out here?

Thanks,
justin_py
Reply
#2
horrible with sql syntax myself but maybe have a look at this
https://www.w3schools.com/sql/sql_insert.asp
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 182 Yesterday, 09:55 PM
Last Post: deanhystad
  Mysql and mysql.connector error lostintime 2 664 Oct-03-2023, 10:25 PM
Last Post: lostintime
  python script for inserting rows into hbase table lravikumarvsp 7 7,097 Mar-24-2023, 04:44 AM
Last Post: parth_botadara
  Basic SQL query using Py: Inserting or querying sqlite3 database not returning data marlonbown 3 1,361 Nov-08-2022, 07:16 PM
Last Post: marlonbown
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,993 Feb-09-2022, 09:55 AM
Last Post: ibreeden
Question Debian 11 Bullseye | Python 3.9.x | pip install mysql-connector-python-rf problems BrandonKastning 4 6,668 Feb-05-2022, 08:25 PM
Last Post: BrandonKastning
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,156 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Reading data from mysql. stsxbel 2 2,202 May-23-2021, 06:56 PM
Last Post: stsxbel
  Python and MySql ogautier 8 3,336 May-20-2021, 11:10 PM
Last Post: Pedroski55
  Python and MySQL Pedroski55 5 3,216 Mar-23-2021, 06:40 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020