Menu

Insert Float Parameter Problem

Help
vodanh
2005-10-17
2012-09-19
  • vodanh

    vodanh - 2005-10-17

    Hello all,

    My am trying to insert a record with a string and a floating parameter, but fail. Please, have a look at my code and give me some advice.

    import MySQLdb

    Vstring = 'string'
    Vfloat = 1.1

    conn = MySQLdb.connect (host = "localhost", user = "root", passwd = "root", db = "test")

    cursor = conn.cursor ()
    cursor.execute ("""INSERT INTO table1(text, num) VALUES (%s,%f)""", (Vstring,Vfloat))
    cursor.execute ("SELECT text, num FROM table1")

    conn.commit()

    cursor.close ()
    conn.close ()

    Thanks in advance.

     
    • vodanh

      vodanh - 2005-10-18

      Thank Andy,

      It works perfectly.

       
    • Andy Dustman

      Andy Dustman - 2005-10-17

      Do this instead:

      cursor.execute ("""INSERT INTO table1(text, num) VALUES (%s,%s)""", (Vstring,Vfloat))

      Next time, post the error traceback.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.