Lib.test.zxjdbc.jndi.py Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jython-installer Show documentation
Show all versions of jython-installer Show documentation
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
# Jython Database Specification API 2.0
#
# Copyright (c) 2001 brian zimmer
"""
This script is used to bind a JNDI reference for testing purposes only.
"""
from java.util import Hashtable
from org.gjt.mm.mysql import MysqlDataSource
from javax.naming import Context, InitialContext, NameAlreadyBoundException
env = Hashtable()
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory")
ds = MysqlDataSource()
ds.setServerName("localhost")
ds.setDatabaseName("ziclix")
ds.setPort(3306)
ctx = InitialContext(env)
try:
try:
ctx.bind("/jdbc/mysqldb", ds)
except NameAlreadyBoundException, e:
ctx.unbind("/jdbc/mysqldb")
ctx.bind("/jdbc/mysqldb", ds)
finally:
ctx.close()
print "bound [%s] at /jdbc/mysqldb" % (ds)