All Downloads are FREE. Search and download functionalities are using the official Maven repository.

docutils.Lib.test.zxjdbc.jndi.py Maven / Gradle / Ivy

There is a newer version: 2.4
Show newest version
# 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)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy