468,538 Members | 1,744 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,538 developers. It's quick & easy.

MySQLdb error - PLEASE SAVE ME!

Ok. I am trying to read a csv file with three strings separated by commas.
I am trying to insert them into a MySQL DB online.
MySQLdb is installed, no problems.

I think that I am having some kind of error with my csv going into the
fields and being broken apart correctly. Can someone please help? I
attached the code below, it does work with that SQL server also if you
want to try and run it. Thanks in advance ..

-----

# Script to add links from a comma deliminated file to a MySQL database
# 9/16/05

import MySQLdb

conn=MySQLdb.connect( host="www.freesql.org",
user="edhotchkiss",
port=3306,
passwd="test1",
db="links")

cursor = conn.cursor()
stmt = "DROP TABLE IF EXISTS links"
cursor.execute(stmt)
stmt = """CREATE TABLE links (
ID INT NOT NULL,
Name TEXT,
URL LONGTEXT,
Category LONGTEXT,
primary key (ID)
)"""
cursor.execute(stmt)
arr=[]
inp = open ("sites1.txt","r")
#read line into array
for line in inp.readlines():
links = map(str, line.split(","))
arr.append(links)
cursor.execute ("""
INSERT INTO links (Name, URL, category)
VALUES (%s, %s, %s)""" % tuple(links[0:3])
)
cursor.close()
conn.close()
--
edward hotchkiss


--
edward hotchkiss

Sep 17 '05 #1
0 1013

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Perflubron | last post: by
1 post views Thread by Derek Fountain | last post: by
2 posts views Thread by ws Wang | last post: by
1 post views Thread by Steve | last post: by
2 posts views Thread by Mondal | last post: by
1 post views Thread by Yi Xing | last post: by
reply views Thread by Edwin.Madari | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.