I am using Jython 2.2.1 and MySQL Connector/J 5.1 to access a MySQL database. I would like to use zxJDBC's cursor.tables() method to retrieve a list of tables in that database. However, this method always returns None.
According to the zxJDBC documentation, cursor.tables() is the same as Java's DatabaseMetaData.getTables(). When I call this Java method from Jython, it works as expected, but using the zxJDBC package doesn't work for me. Here's what I have tried:
import java.sql.*;
public class TableTest {
public static void tables(String url) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url, "root", null);
DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getTables(null, null, "%",
new String[] {"TABLE"});
while (rs.next()) {
System.out.println(rs.getString("TABLE_NAME"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
When I call this from Jython, it is all fine.
from com.ziclix.python.sql import zxJDBC
import TableTest
url = 'jdbc:mysql://localhost/jythontest'
print 'Java:'
TableTest.tables(url);
print 'Python:'
conn = zxJDBC.connect(url, 'root', None, 'com.mysql.jdbc.Driver')
cursor = conn.cursor()
print cursor.tables(None, None, '%', ('TABLE',))
There are two tables in my test database called 'table_a' and 'table_b'. The output is:
Java:
table_a
table_b
Python:
None
I have tried this on Linux and on MacOS with the same result. Before I try to figure out what's wrong with zxJDBC, I wanted to know whether there is anything wrong in the way I am using this package.
Thank you.