Jython zxJDBC.cursor fetchone() 对于会话变量,我得到一个数组
我使用Jython2.5.0,mysql-connector-java-5.0.8-bin.jar,因为我的服务器是Mysql5.0.38 我的 Jython 应用程序存在问题。
两个函数:
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
然后我做了这样的事情:
query = """SELECT count(*) from test_db.test_table1 into @max"""
act_query(query)
get_query= """ select @max """
row = get_row(get_query)
print row
输出类似于: array('b', [49, 52, 54, 50, 56, 48, 52])
我尝试找到原因并进行如下测试:
test_query = """select count(*) from test_db.test_table1"""
row = get_row(test_query)
print row
输出是正确的答案
事实上,这是一个 CPython 脚本,首先使用 MySQLdb,然后我使用 zxJDBC 将其转换为 Jython
它在 CPython 中运行良好,但现在无法运行。
在CPython中,游标可以定义为
cursor = connection.cursor(MySQLdb.cursors.DictCursor)
,但在zxJDBC中,似乎没有选择创建游标。
是这个原因吗?
请给我指路。谢谢!
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 choice for creating a cursor.
Is this the reason?
Please show me the way. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从 jython mailist 得到了答案。
JDBC获取的会话变量是varbinary类型。 zxJDBC将其转为数组,通过str(byte[])将数组转为int即可得到正确的输出。
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[]).