This program runs and then at the end where i select the entire database and read it out to the console i see the results. The issue i am having is that when i go to the actual access database there is no changes and it is still blank.
Any help would be much appreciated.
Be kind as this is my first day on python :$
Thanks
Code:
import os
import adodbapi
database = "db1.mdb"
constr = 'Provider=Microsoft.Jet.OLEDB.4.0; Data Source=%s' % database
tablename = "address"
# connect to the database
conn = adodbapi.connect(constr)
# create a cursor
cur = conn.cursor()
path = 'XXXXXXXX'
listing = os.listdir(path)
i = 0
for infile in listing:
i + 1
try:
if infile.endswith('.xml'):
print('File: ' + path + infile)
from xml.dom import minidom
xmldoc = minidom.parse(path + infile)
xfadata = xmldoc.getElementsByTagName("xfa:data")[0]
CostDealsForm = xfadata.getElementsByTagName("CostDealsForm")[0]
P1 = CostDealsForm.getElementsByTagName("P1")[0]
RefSub = P1.getElementsByTagName("RefSub")[0]
RefNum = RefSub.getElementsByTagName("RefNum")[0].firstChild.data
Date = RefSub.getElementsByTagName("Date")[0].firstChild.data
#print(RefNum, Date)
# extract all the data
sql2 = "select * from %s" % tablename
sql = "INSERT INTO %s (Reference_Number, Date1) Values ('" %tablename + RefNum + "', '"+ Date + "');"
cur.execute(sql)
cur.commit(sql)
except AttributeError:
RefNum = 'Error'
Date = 'Error'
sql = "INSERT INTO %s (Reference_Number, Date1) Values ('" %tablename + RefNum + "', '"+ Date + "');"
cur.execute(sql)
cur.execute(sql2)
# show the result
result = cur.fetchall()
for item in result:
print item
# close the cursor and connection
cur.close()
conn.close()
Be kind as this is my first day on python :$
Thanks
Comment