Jython zxJDBC.cursor fetchone() 对于会话变量,我得到一个数组

发布于 2024-08-03 11:27:54 字数 1259 浏览 1 评论 0原文

我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

池予 2024-08-10 11:27:54

我从 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[]).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文