Skip to content

Instantly share code, notes, and snippets.

@linkerlin
Created January 28, 2013 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linkerlin/4656261 to your computer and use it in GitHub Desktop.
Save linkerlin/4656261 to your computer and use it in GitHub Desktop.
A demo for using mysql in Jython.
from __future__ import with_statement
from com.ziclix.python.sql import zxJDBC
import sys
#sys.path+=[r'/home/linker/jars/mysql-connector-java.jar']
#sys.path+=[r'/home/linker/jarss/']
from classpathhacker import *
jarloader=classPathHacker()
#jarloader.addFile(r'/home/linker/jars/mysql-connector-java.jar')
jdbc_url = "jdbc:mysql://localhost:3306/test"
username = "root"
password = "1"
driver = "com.mysql.jdbc.Driver"
# obtain a connection using the with-statment
with zxJDBC.connect(jdbc_url, username, password, driver) as conn:
with conn:
with conn.cursor() as c:
c.execute("select name from country")
print c.fetchone()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment