tags:

views:

181

answers:

1

I use Jython2.5.0, mysql-connector-java-5.0.8-bin.jar, because my sever is Mysql5.0.38 There is a problem in my Jython application.

Two functions:

def act_query(query):
connection = conn //conn is global and has been assigned when called
cursor = connection.cursor()
num_affected_rows = cursor.execute(query)
cursor.close()
connection.commit()
return num_affected_rows

def get_row(query):
connection = conn
cursor = connection.cursor()
cursor.execute(query)
row = cursor.fetchone()
cursor.close()
return row

Then i do something like this:
query = """SELECT count(*) from test_db.test_table1 into @max"""
act_query(query)
get_query= """ select @max """
row = get_row(get_query)
print row
The output is something like: array('b', [49, 52, 54, 50, 56, 48, 52])

I try to find the reason and make a test like:
test_query = """select count(*) from test_db.test_table1"""
row = get_row(test_query)
print row
The output is the right answer

In fact this a script in CPython first with MySQLdb and I turn it into Jython with zxJDBC
It worked well in CPython but It can't work now.
In CPython the cursor can be defined as
cursor = connection.cursor(MySQLdb.cursors.DictCursor)
but in zxJDBC there seem to be no choise for creating a cursor.
Is this the reason?
Please show me the way. Thanks!

+1  A: 

I got the answer from jython mailist. A session variable get by JDBC is of varbinary type. zxJDBC make it to be an array.The right output can be get by converting the array into int with str(byte[]).

Ke Zhifeng