Newbie Wondering About Database Support?
Max
maxx at easynews.com
Wed Dec 19 13:17:46 EST 2001
On Tue, 18 Dec 2001 20:13:17 -0000, richardkessler at matteicos.com (Richard
Kessler) wrote:
>I have recently discovered Python and am excited about the possibility of
>developing with the language. Unfortunately, I develop database centric
>applications, MS SQL Server, etc. and I do not see much talk about Python and
>access to databases. Am I missing something or is Python not intended for that
>purpose. I would love to replace programs currently in VB with Python, but
>they must be able to access databases.
For connectivity to SQL Server, if the code in running under Windows, see the
examples at http://www.e-coli.net/pyado.html . You will see ADO being used to
connect to a Jet/Access database, but the technique is very similar with MS SQL.
A simplistic example of Python code accessing a SQL Server follows:
import sys, win32com.client
adoConn = win32com.client.Dispatch('ADODB.Connection')
connect = "Provider=SQLOLEDB.1;Data Source=TestServer;Initial Catalog=pubs;User
ID=sa;Password=;"
sql = "SELECT lname FROM employee"
adoConn.Open(connect)
db = adoConn.Execute(sql)
while not db[0].EOF:
lastname=db[0].Fields(0).Value
print lastname
db[0].MoveNext()
More information about the Python-list
mailing list