def __init__(self, classpath=''): skjar_file = 'SpatialKappa-v2.1.1.jar' antlrjar_file = 'ant-antlr-3.2.jar' skjar_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'share', 'SpatialKappa', skjar_file) antlrjar_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'share', 'SpatialKappa', antlrjar_file) classpath = os.pathsep.join((classpath, skjar_path, antlrjar_path)) print classpath self.port = jg.launch_gateway(classpath=classpath, die_on_exit=True) self.gateway_client = jg.GatewayClient(port=self.port) self.gateway = jg.JavaGateway(self.gateway_client)
def connect(jclassname, driver_args, jars=None, libs=None): """Open a connection to a database using a JDBC driver and return a Connection instance. jclassname: Full qualified Java class name of the JDBC driver. driver_args: Argument or sequence of arguments to be passed to the Java DriverManager.getConnection method. Usually the database URL. See http://docs.oracle.com/javase/6/docs/api/java/sql/DriverManager.html for more details jars: Jar filename or sequence of filenames for the JDBC driver libs: Dll/so filenames or sequence of dlls/sos used as shared library by the JDBC driver """ if _gateway_is_running(): gateway = java_gateway.JavaGateway() else: driver_args = [driver_args] if isinstance(driver_args, str) else driver_args if jars: classpath = os.pathsep.join(jars) if isinstance(jars, list) else jars else: classpath = None if libs: javaopts = libs if isinstance(libs, list) else [libs] else: javaopts = [] gateway = java_gateway.JavaGateway.launch_gateway(port=25333, classpath=classpath, javaopts=javaopts, die_on_exit=True) java_gateway.java_import(gateway.jvm, 'java.sql.DriverManager') gateway.jvm.Class.forName(jclassname) connection = gateway.jvm.DriverManager.getConnection(*driver_args) if _converters is None: types_map = {} for type in gateway.jvm.Class.forName("java.sql.Types").getFields(): types_map[type.getName()] = type.getInt(None) _init_converters(types_map) return Connection(connection, _converters)
# coding: utf-8 from py4j import java_collections from py4j import java_gateway gtwyCl = java_gateway.GatewayClient() java_collections.JavaArray("foo", gtwyCl) # AttributeError: 'NoneType' object has no attribute 'auto_field' java_gateway.JavaGateway(self, gateway_client=None, auto_field=False, python_proxy_port=25334, start_callback_server=False, auto_convert=False, eager_load=False, gateway_parameters=None, callback_server_parameters=None, python_server_entry_point=None)