【问题标题】:Python inserting list of alphanumeric strings into databasePython将字母数字字符串列表插入数据库
【发布时间】:2014-06-01 17:51:13
【问题描述】:

我想在表中插入一个字母数字字符串列表,但这个似乎不起作用,因为表已构建但数据未插入

con = mdb.connect('localhost', 'root', 'qwerty123', 'testdb');
    cur = con.cursor()
    cur.execute("DROP TABLE IF EXISTS alphanum")
    cur.execute("CREATE TABLE alphanum(Name VARCHAR(25))")
    j=64
    test1 = []
    for i in range(0,26):
        j+=1
        test1.append(j)
        test1.append(j+32)

    for i in range(0,52):
        print chr(test1[i])


    for a in range(0,4):
        for b in range(0,52):
            for c in range(0,52):
                result = chr(a+48)+chr(test1[b])+chr(test1[c])
                print result
                for entry in result:
                    cur.execute("INSERT INTO alphanum VALUES(%s)",(result))

以下是一些结果示例:

0AA
0Aa
0AB
0Ab
0AC
0Ac
0AD
0Ad
0AE
0Ae
0AF
0Af
0AG
0Ag
0AH
0Ah
0AI
0Ai
0AJ

【问题讨论】:

    标签: python mysql database python-2.7 alphanumeric


    【解决方案1】:

    是的,您必须使用

    提交更改
    con.commit()
    

    否则更改将不会反映在数据库中。

    【讨论】:

      【解决方案2】:

      你忘了提交:

      con.commit()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-04
        • 1970-01-01
        • 2014-04-02
        相关资源
        最近更新 更多