Dear John,

 i“m using Jython scripts based on standard Java JDBC interfaces and
this works well for me. My applications are running under DB2 databases
and i“ve chosen two types of driver implementations:
 
  A) ODBC based SQL drivers for Windows;
  B) DB2 to JDBC (type 4) drivers for LINUX;      
 
 The ODBC based driver are also visible to Windows, or you can choose
a JDBC compliant Java driver delivered by the database vendor.    

You will find the available drivers from a download page of MySQL:
http://dev.mysql.com/downloads/

For ex. the ODBC<->JDBC driver called "Connector/ODBC" and JDBC Java
driver called "MySQL Connector/J".  Both will do the connectivity.

 Let me copy here some of the Jython statements to illustrate the difference:

Sample for A (JDBC<->ODBC):

from java.sql import *
from java.net.URL import *

# load DB2 JDBC type 2 driver (app driver)
urlstring = "sun.jdbc.odbc.JdbcOdbcDriver"
Class.forName(urlstring).newInstance()

# setup the properties
prop = Properties()
prop.put("user", username)
prop.put("password", password)

# Load the JDBC-ODBC bridge driver
url = "jdbc:odbc:" + dbname
conn = DriverManager.getConnection(url, prop)
stmt = conn.createStatement()
if stmt.execute(query):
     rs.next()
     rowcnt = rs.getInt(1)
     ..
 

Sample for B (DB2 type for 4 drivers):

from java.sql import *
from java.net.URL import *

# load DB2 JDBC type 4 driver (app driver)
Class.forName("com.ibm.db2.jcc.DB2Driver")        
     
# Load the JDBC type 4 driver
url = "jdbc:db2://localhost:60000/" + dbname
conn = DriverManager.getConnection(url,username,password)
stmt = conn.createStatement()
if stmt.execute(query):
     rs.next()
     rowcnt = rs.getInt(1)
     ..

Have fun with Jython.

Regards,
Claude

Claude Falbriard
Developer
AMS Hortolāndia / SP - Brazil
phone: +55 13 8117 3316
e-mail:  claudef@br.ibm.com



"jh" <john@datavoiceint.com>
Sent by: jython-users-bounces@lists.sourceforge.net

27/06/2007 13:11

To
<jython-users@lists.sourceforge.net>
cc
Subject
[Jython-users] MySQL





I am using a tool called maxq that is written in jython and I want to make
some MySQL queries from my test script. It looks like zxJDBC is available as
the following lines execute OK but complains that the driver was not found.
I picked up the driver name from the jython page
http://www.jython.org/docs/zxjdbc.html. The driver name seems a bit unusual
but other examples have multi-dotted names too. I also added
mysql-connector-java-5.0.6-bin to the jar lib and the CLASSPATH and tried
their driver names to no avail.

Don't know much about jython per se but if you have any insight or ideas
about accessing MySQL please sing out.

Thanx,

jh


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from com.ziclix.python.sql import zxJDBC
       d, u, p, v = "jdbc:mysql://localhost", 'admin', 'myPassword',
"org.gjt.mm.mysql.Driver"
       db = zxJDBC.connect(d, u, p, v)


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users