WEB开发网
开发学院数据库DB2 在 DB2 V9 for z/OS 中通过类型 2 连接支持多行获... 阅读

在 DB2 V9 for z/OS 中通过类型 2 连接支持多行获取

 2010-02-05 00:00:00 来源:WEB开发网   
核心提示: 该程序将 enableRowsetSupport 设置为 YES,这意味着将启用 MRF,在 DB2 V9 for z/OS 中通过类型 2 连接支持多行获取(3),importjava.sql.*;publicclassconnectionInfo_MRF{publicstaticvoidma

该程序将 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(); 
  
 } 
} 

上一页  1 2 3 4 5  下一页

Tags:DB for OS

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接