exceptionerror

Asked by mali

Hello , i got error when debug my program . Exception: Not All parameters were used in the SQL statement. What should i do ? How can write values of strings?

#-----------------------------------------------------------------------------------
#Connect MySQL
#-----------------------------------------------------------------------------------

cnx = mysql.connector.connect(user='root',password='test',
                              host='localhost',
                              database='Temperature')

cursor= cnx.cursor()

#-----------------------------------------------------------------------
#MPU-DATA
#-----------------------------------------------------------------------
math functions
  math functions
  .
  .
  .
collect accel and gyro datas

  .
  x= x/scaler
  y= y/scaler
  z=z/scaler
  return {'x': x, 'y': y, 'z': z}

def get_all_data(self):
  gyro = get_gyro_data()

#-----------------------------------------------------------------------------------
#Insert new data
#-----------------------------------------------------------------------------------

while True :
    mpu = MPU6050(0x68)
    accel_data = mpu.get_accel_data()
    print(accel_data['x'])
    print(accel_data['y'])
    print(accel_data['z'])
    gyro_data = mpu.get_gyro_data()
    print(gyro_data['x'])
    print(gyro_data['y'])
    print(gyro_data['z'])
    Time = (time.strftime("%H:%M:%S"))
    Date = (time.strftime("%Y-%m-%d"))
    print (Time + " - " + Date)
    sql = ("""INSERT INTO `TAB_TEMP` (`Date`,`Time`,`JX`,`JY`,`JZ`,`IX`,`IY`,`IZ`) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)"""
    args = (Date,Time,accel_data['x'],accel_data['y'],accel_data['z'],gyro_data['x'],gyro_data['y'],gyro_data['z']))
    try:

        print ("Writing to database...")
        # Execute the SQL command
        cursor.execute(sql,args)
        # Apply changes
        cnx.commit()
        print ("Write Complete")

    except:

        # Rollback if error appears
        cursor.close()
        cnx.close()
        print ("Failed writing to database")

Question information

Language:
English Edit question
Status:
Expired
For:
MySQL Connector/Python Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.