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:
My Questions:
- Can we use VSE Redirector Connector to read VSAM files? If yes, then how can we resolve the above error and get connected?
- Is there any other method to access VSAM files thru Java?