在 DB2 V9 for z/OS 中通过类型 2 连接支持多行获取
2010-02-05 00:00:00 来源:WEB开发网该程序将 enableRowsetSupport 设置为 YES,这意味着将启用 MRF。
import java.sql.*;
public class connectionInfo_MRF
{
public static void main(String[] args) throws Exception
{
System.out.println("\nTest case begins !!!\n ");
javax.sql.DataSource ds = new com.ibm.db2.jcc.DB2SimpleDataSource();
((com.ibm.db2.jcc.DB2BaseDataSource) ds).setServerName("ServerName");
((com.ibm.db2.jcc.DB2BaseDataSource) ds).setPortNumber(portNumber);
((com.ibm.db2.jcc.DB2BaseDataSource) ds).setDatabaseName("databaseName");
((com.ibm.db2.jcc.DB2BaseDataSource) ds).setDriverType(2);
// Enable MRF support. To disable MRF, set setEnableRowsetSupport
// to com.ibm.db2.jcc.DB2BaseDataSource.YES
int setValue = com.ibm.db2.jcc.DB2BaseDataSource.YES;
((com.ibm.db2.jcc.DB2BaseDataSource)ds).setEnableRowsetSupport(setValue);
((com.ibm.db2.jcc.DB2BaseDataSource) ds).setTraceFile("jccTrace.txt");
System.out.println(((com.ibm.db2.jcc.DB2BaseDataSource) ds).getJccVersion());
java.sql.Connection con = ds.getConnection("userName", "passWord");
// Get Rowset support value. When MRF is enabled this should return value 1.
int RowSet = ((com.ibm.db2.jcc.DB2BaseDataSource)ds).getEnableRowsetSupport();
System.out.println("\nRow Set Support value :" +RowSet);
System.out.println("\n");
// Set the cursor type to scrollable.
//Modify the below statement if you want the cursor type to be TYPE_FORWARD_ONLY
java.sql.Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
// Create table
s.executeUpdate ("create table TestQBatch (col1 int)");
// Populate tables with data.
for (int i =1; i less than 1000; i++)
{
s.executeUpdate ("insert into TestQBatch values (" +i+ ")");
}
java.sql.ResultSet rs = s.executeQuery("Select * from TestQBatch");
while (rs.next())
{
System.out.print (rs.getInt (1) + " ");
}
// When MRF is enabled, ResultSet.getFetchSize() should alway return value > 1.
int ActualResult = rs.getFetchSize();
System.out.print ("\n\nFetch Size : " +ActualResult);
// Drop the table created.
s.executeUpdate("DROP TABLE TestQBatch");
System.out.println("\n\nTest case Ends !!! ");
con.commit();
}
}
- ››db2 对float类型取char后显示科学计数法
- ››DB2中出现SQL1032N错误现象时的解决办法
- ››DB2 锁升级示例
- ››db2诊断系列之---定位锁等待问题
- ››Form Reset Function
- ››OSC“回到顶部”代码
- ››db2 命令选项解释
- ››OSCHINA 使用 Github 登录的源码
- ››FOREACH 宏之GCC实现
- ››DB2 最佳实践: 使用 DB2 pureXML 管理 XML 数据的...
- ››DB2 9.5 SQL Procedure Developer 认证考试 735 准...
- ››DB2 9.5 SQL Procedure Developer 认证考试 735 准...
更多精彩
赞助商链接