python 处理返回数据页面的SQL查询(多个ResultSet对象)。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 处理返回数据页面的SQL查询(多个ResultSet对象)。相关的知识,希望对你有一定的参考价值。

import com.ziclix.python.sql.zxJDBC as zxJDBC

# In place of this, imagine a complicated query returning multiple ResultSet instances.
fancyApiCursorQuery = 'SELECT MyColumn FROM MyTable'

url='jdbc:sqlserver://sqlserver-host:1433;database=MyBigDatabase'
user='mario'
pw='myP@ssw0rd'
driver='com.microsoft.sqlserver.jdbc.SQLServerDriver'

conn = zxJDBC.connect(url, user, pw, driver)
try:
    # We're going to have to use the JDBC connection directly for this fancy stuff.
    jdbcConn = conn.__connection__
    stmt = jdbcConn.createStatement()
    stmt.execute(fancyApiCursorQuery)
    rs = None
    while True:
        # Loop through the set of ResultSet objects.
        rs = stmt.getResultSet()
        while rs.next():
            print rs.getString('MyColumn')
        if stmt.getMoreResults() == False and stmt.getUpdateCount() == -1:
            # We have no more ResultSet objects.
            break
    if rs:
        rs.close()
    stmt.close()
finally:
    if conn:
        conn.close()
        

以上是关于python 处理返回数据页面的SQL查询(多个ResultSet对象)。的主要内容,如果未能解决你的问题,请参考以下文章