[Tutor] Simple SQL server access...

Andrew Robert andrew.arobert at gmail.com
Thu Sep 7 03:11:29 CEST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chris Hengge wrote:
> I've been doing some searching for ways to access existing SQL server
> databases, but I'm finding so many different ways to do it, is there one
> that anyone recommends for a "new to python" programmer? I've used VB
> and C# for accessing SQL, so maybe something that would feel similiar to
> that to get me started?
>  
> Thanks.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


How about something like this?

I use it for connecting to Oracle databases.

Information on cx_Oracle and similar can be found at
http://www.python.net/crew/atuining/cx_Oracle/




import cx_Oracle

class db:
    def __init__(self, db, uname, passwd):
        self.connection =
cx_Oracle.connect(dsn=db,user=uname,password=passwd)

    def execute(self, sql):
        cursor = self.connection.cursor()
        cursor.execute(sql)
        return cursor

    def close(self):
        self.connection.close()
        self.connection = None # Prevent reusing a closed connection
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)
Comment: GnuPT 2.7.2

iD8DBQFE/3HBDvn/4H0LjDwRAqPlAKCPFY6uzHHHWQ4ZKrq3BfqQy9QufgCfZs0a
Zj69XcmwAlW4L+HbH56Wxf8=
=yMOb
-----END PGP SIGNATURE-----


More information about the Tutor mailing list