MySQL Error #1064 in Python Programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cpiyush
    New Member
    • Jan 2007
    • 31

    #1

    MySQL Error #1064 in Python Programming

    Hello,

    I am trying to insert values in a MySQL table using Python as front end, but facing this problem.

    table structure:-(Name:- namespace)
    Fields
    prifex-----------------varchar(20)
    namespace--------varchar(100)

    Code:-
    Code:
    	global prefix_dict
    	global dbConn
    
    	keys=[]
    	i=0
    	prefix=''
    	nmspace=''
    
    	keys=prefix_dict.keys()
    	
    	while i<len(keys):
    		prefix=keys[i]
    		nmspace=prefix_dict[keys[i]]
    		s="""("""+str(prefix)+""","""+str(nmspace)+""")"""
    		print "--------------------------------------------"
    		print s
    		print "--------------------------------------------"
    		s1="""INSERT INTO namespace VALUES"""+s
    		print s1
    		dbConn.query(s1)
                                    i+=1
    Output:-

    --------------------------------------------
    (default,<http://Demo:Remo@172.2 1.107.145:8080/SfleXProd/#>)
    --------------------------------------------
    Code:
    INSERT INTO namespace VALUES(default,<http://Demo:Remo@172.21.107.145:8080/SfleXProd/#>)
        dbConn.query(s1)
    _mysql_exceptio ns.ProgrammingE rror: (1064, "You have an error in your SQL syntax
    ; check the manual that corresponds to your MySQL server version for the right s
    yntax to use near '<http://Demo:Remo@172.2 1.107.145:8080/SfleXProd/#>)' at line
    1")


    Problem:-
    I am using variable names instead of literal values in the insert statement & not getting the correct syntax, although when I am using literal values i am getting the success.

    plz help me that how to use variable names in insert query.
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by cpiyush
    Hello,

    Problem:-
    I am using variable names instead of literal values in the insert statement & not getting the correct syntax, although when I am using literal values i am getting the success.

    plz help me that how to use variable names in insert query.
    I do that all the time. See this thread.

    Comment

    Working...