title: Connecting and testing a JDBC driver from Python
body: <p>I'm trying to do some testing on our JDBC driver using Python. </p>
  
  <p>Initially figuring out JPype, I eventually managed to connect the driver and execute select queries like so (reproducing a generalized snippet):</p>
  
  <pre><code>from __future__ import print_function
  from jpype import *
  
  #Start JVM, attach the driver jar
  jvmpath = 'path/to/libjvm.so'
  classpath = 'path/to/JDBC_Driver.jar'
  startJVM(jvmpath, '-ea', '-Djava.class.path=' + classpath)
  
  # Magic line 1
  driver = JPackage('sql').Our_Driver
  
  # Initiating a connection via DriverManager()
  jdbc_uri = 'jdbc:our_database://localhost:port/database','user', 'passwd')  
  conn = java.sql.DriverManager.getConnection(jdbc_uri)
  
  # Executing a statement
  stmt = conn.createStatement()
  rs = stmt.executeQuery ('select top 10 * from some_table')
  
  # Extracting results
  while rs.next():
      ''' Magic #2 - rs.getStuff() only works inside a while loop '''
      print (rs.getString('col_name'))
  </code></pre>
  
  <p>However, I've failed to to batch inserts, which is what I wanted to test. Even when <code>executeBatch()</code> returned a jpype int[], which should indicate a successful insert, the table was not updated. </p>
  
  <p>I then decided to try out py4j. </p>
  
  <p>My plight - I'm having a hard time figuring out how to do the same thing as above. It is said py4j does not start a JVM on its own, and that the Java code needs to be prearranged with a GatewayServer(), so I'm not sure it's even feasible. </p>
  
  <p>On the other hand, there's a library named <a href="https://github.com/massmutual/py4jdbc" rel="nofollow noreferrer">py4jdbc</a> that does just that. </p>
  
  <p>I tinkered through the dbapi.py code but didn't quite understand the flow, and am pretty much jammed.</p>
  
  <p>If anyone understands how to load a JDBC driver from a .jar file with py4j and can point me in the right direction, I'd be much grateful. </p>