Académique Documents
Professionnel Documents
Culture Documents
1
Me
• Frank Joseph Wierzbicki
(frank.wierzbicki@sun.com)
• Project lead for Jython
• Java Developer for 10 years
• Python/Jython Developer for 10 years
• Contributor to Jython for 4+ years
def hello(name):
print “hello”, name
7
Jython and JDBC
• Jython has built in support for DB-API, Python's
standard database interface in the zxJDBC
package.
• zxjdbc is a thin wrapper around JDBC, Java's
standard database interface.
• Provides Python programmers with access to any
database with a JDBC driver.
• Provides Java programmers with access to any
Python frameworks that are built on DB-API
db = zxJDBC.connect("jdbc:mysql://localhost/test",
'user', 'pass', "org.gjt.mm.mysql.Driver")
cursor = db.cursor()
cursor.execute("select name from user")
for row in cursor.fetchall():
cursor.close()
db.close()
11
Django
• A Python MVC framework with a web and database
bias (similar to Ruby on Rails)
• Makes creating a project very simple
• Comes with a powerful admin tool that can be used
to manage the data in your database – no need to
write your own admin tool!
• Very clean and simple design, easy to read and
write.
13
Hibernate From Jython
• Hibernate is a ORM written in Java
• It can be accessed as EJB3
• Jython can be used
16
SQLAlchemy
• SQLAlchemy is a ORM written in pure Python
• Written by Michael Bayer who consults on
Hibernate by day
• Utilizes Python's strengths to create very clear ORM
code
db = create_engine('mysql://mydb:mydb@localhost/mydb')
metadata = MetaData(db)
continents = Table('continent', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(40)),
)
s = continents.select()
r = s.execute()
for continent in r:
print continent.name