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

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

Go to download

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.

There is a newer version: 2.7.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