调用Sybase Adaptive Server Enterprise的"sp_help".来自JDBC [英] Calling Sybase Adaptive Server Enterprise's "sp_help" from JDBC

查看:119
本文介绍了调用Sybase Adaptive Server Enterprise的"sp_help".来自JDBC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在Sybase ASE中查询数据库元数据,我发现这个相关答案(不是公认的答案)是理想的:

In order to query the database meta data in Sybase ASE, I found this relevant answer (not the accepted one), to be ideal:

如何从Sybase数据库中获取表描述(字段名称和类型)?

不幸的是,我似乎找不到任何文档,应该如何从JDBC调用sp_help.根据

Unfortunately, I can't seem to find any documentation, how I'm supposed to call sp_help from JDBC. According to the documentation, sp_help returns several cursors / result sets. The first one contains information about the table itself, the second one about the columns, etc. When I do this:

PreparedStatement stmt = getConnection().prepareStatement("sp_help 't_language'");
ResultSet rs = stmt.executeQuery();

while (rs.next()) {
    System.out.println(rs.getObject(1));
    // ...
}

我只从第一个光标得到结果.如何访问其他人?

I only get the results from the first cursor. How to access the other ones?

推荐答案

当您有多个结果集时,需要使用

When you have multiple result sets you need to use the execute() method rather than executeQuery(). Here's an example:

CallableStatement cstmt;
ResultSet rs;
int i;
String s;
...
cstmt.execute();                        // Call the stored procedure       1 
rs = cstmt.getResultSet();              // Get the first result set        2 
while (rs.next()) {                     // Position the cursor             3 
 i = rs.getInt(1);                      // Retrieve current result set value
 System.out.println("Value from first result set = " + i);  
                                        // Print the value
}
cstmt.getMoreResults();                 // Point to the second result set  4a 
                                        // and close the first result set
rs = cstmt.getResultSet();              // Get the second result set       4b 
while (rs.next()) {                     // Position the cursor             4c 
 s = rs.getString(1);                   // Retrieve current result set value
 System.out.println("Value from second result set = " + s); 
                                        // Print the value
}
rs.close();                             // Close the result set
cstmt.close();                          // Close the statement 

这篇关于调用Sybase Adaptive Server Enterprise的"sp_help".来自JDBC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆