From: Robert W. B. <rb...@di...> - 2001-08-06 17:25:43
|
*Moved to Jython-users On Tue, 7 Aug 2001, syKim wrote: > Hello > > I am trying web program with jython.. > > It have to use database. and, I tried mysql.. > > in python, Mysql-python module exist (a kind of plug-in module) > > but, it is just occasion of Cpython.. > > How can I use Mysql under jython? Is it possible? Oh yes, it is possible. You get to choose using JDBC directly or the wonderful Python DB API 2.0 zxjdbc package. I use zxJDBC mostly now because of the convenience it offers (tnx Brian!). Check it out at www.ziclix.com/zxjdbc You do need the java jdbc driver. It is available at www.mysql.org (click on "downloads" then "Contributed software"). Look for the mm.mysql.jdbc-0.6.tar.gz package- it's the java jdbc driver you want. using JDBC is as simple as below (untested though, there's probably a typo): >>> import java >>> java.lang.Class.forName("org.gjt.mm.mysql.Driver") >>> con = java.sql.DriverManager.getConnection( "jdbc:mysql://host/database","username","passwd"); >>> Stmt = con.createStatement(); >>> rs = Stmt.executeQuery("SELECT * from sometable"); >>> >>> while (rs.next()): print rs.getString("field") zxJDBC usage is best gotten from the nice documentation that comes with it. The examples Brian includes with zxJDBC are specific to mysql- I'm sure you will find them most helpful (www.ziclix.com/zxjdbc/documentation.html). Don't hesitate with future questions- there's a horde of database gurus that lurk about in this list :) Cheers, Robert |