Created
January 28, 2013 15:15
-
-
Save linkerlin/4656261 to your computer and use it in GitHub Desktop.
A demo for using mysql in Jython.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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