2

I am trying to connect to VSAM files in z/OS in Java. I have tried using VSE Redirector Connector with below code:

package test;

import java.sql.DriverManager;
import java.sql.ResultSetMetaData;

public class TestVSAM {

  public static void main(String[] args) {

    String vsamCatalog = "VSESP.USER.CATALOG";
    String flightsCluster = "USERNAME.TEST.KSDS1";
    String flightsMapName = "FLIGHTS_MAP";
    
    String ordersCluster = "FLIGHT.ORDERING.ORDERS";
    String ordersMapName = "ORDERS_MAP";

    String ipAddr = "XXX.XXX.XXX.XXX";
    String userID = "XXXXXX";
    String password = "XXXXXX";
    Integer port = 123;

    try {
      System.out.println("VSE IP address------------->" + ipAddr);

      System.out.println("Your VSE user ID----------->" + userID);

      System.out.println("Password------------->" + password);

      System.out.println("Port------------->" + port);

      java.sql.Connection jdbcCon;
      java.sql.Driver jdbcDriver =
          (java.sql.Driver) Class.forName("com.ibm.vse.jdbc.VsamJdbcDriver").newInstance();

      // Build the URL to use to connect
      String url = "jdbc:vsam:" + ipAddr;

      // Assign properties for the driver
      java.util.Properties prop = new java.util.Properties();
      prop.put("port", port);
      prop.put("user", userID);
      prop.put("password", password);

      // Connect to the driver
      jdbcCon = DriverManager.getConnection(url, prop);

      // Get a statement
      java.sql.Statement stmt = jdbcCon.createStatement();

      // Execute the query ...
      java.sql.ResultSet rs = stmt.executeQuery(
          "SELECT * FROM " + vsamCatalog + "\\" + flightsCluster + "\\" + flightsMapName);

      ResultSetMetaData rsmd = rs.getMetaData();
      int columnCount = rsmd.getColumnCount();

      for (int i = 1; i <= columnCount; i++) {
        System.out.println("Key------------>" + rsmd.getColumnLabel(i));

      }
      rs.close();
      stmt.close();

    } catch (Exception e) {
      System.out.println(e);
    }

I'm getting this error:

Connection Refused Error

My Questions:

  1. Can we use VSE Redirector Connector to read VSAM files? If yes, then how can we resolve the above error and get connected?
  2. Is there any other method to access VSAM files thru Java?
Hogstrom
  • 3,581
  • 2
  • 9
  • 25
  • Please, post your error as text rather than as an image (text is searchable, images are not; text can be copied-pasted, images cannot). – Dada Nov 03 '21 at 11:16
  • I don't know `VSE Redirector Connector`, but VSE is not z/OS. These are two different IBM mainframe operating systems. – phunsoft Nov 03 '21 at 16:03
  • 2
    Can you clarify what you are trying to accomplish? You're using a VSE component that enables access to VSAM on VSE. Is your goal to process VSAM files on VSE from z/OS or access VSAM files on z/OS using the VSE tool? A picture is worth a 1000 words. The problem you are having is the endpoint you are trying to connect to is likely not running. – Hogstrom Nov 03 '21 at 18:36
  • @Hogstrom - I was trying to connect to VSAM files on z/OS and opted for this VSE redirector method but looks like this is useful for accessing VSE but not z/OS. – S Swetha Bathulapalli Nov 10 '21 at 05:57

1 Answers1

0

Have you considered something like: https://www.ibm.com/docs/en/sdk-java-technology/8?topic=jzos-zfile