使用Java JDBC写入VSAM文件时将其锁定 [英] VSAM file locking when writing to it using Java JDBC

查看:223
本文介绍了使用Java JDBC写入VSAM文件时将其锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次尝试读取和写入VSAM文件.我所做的是:

This is my first time trying to read and write to a VSAM file. What I did was:

  1. 使用VSE导航器为文件创建地图
  2. 将Java bean VSE连接器库添加到我的Eclipse Java项目中
  3. 使用下面显示的代码来写入和读取KSDS文件.

读取文件不是问题,但是当我尝试写入文件时,仅当我在运行Java程序之前进入大型机并关闭File时,该文件才有效,但它会将文件锁定了一个小时.您无法在大型机上打开文件或对其执行任何操作.

Reading the file is not a problem but when I tried to write to the file it only works if I go on the mainframe and close the File before running my java program but it locks the file for like an hour. You cannot open the file on the mainframe or do anything to it.

任何人都可以帮助解决此问题.我需要为大型机上的文件设置一个特殊的设置吗?为什么首先需要关闭CICS上的文件才能写入文件?为何在写入文件后锁定文件?

Anybody can help with this problem. Is there a special setting that I need to set up for the file on the mainframe ? Why do you first need to close the file on CICS to be able to write to it ? And why does it locks the file after writing to it ?

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.*;
public class testVSAM {

public static void main(String argv[]){
    Integer test = Integer.valueOf(2893);
    String vsamCatalog = "VSESP.USER.CATALOG";
    String FlightCluster = "FLIGHT.ORDERING.FLIGHTS";       
    String FlightMapName = "FLIGHT.TEST2.MAP";
    try{

        String ipAddr = "10.1.1.1";                     
        String userID = "USER1";            
        String password = "PASSWORD"; 

        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", test);
        prop.put("user", userID);
        prop.put("password", password);
        // Connect to the driver
        jdbcCon = DriverManager.getConnection(url,prop);

        try {
            java.sql.PreparedStatement pstmt = jdbcCon.prepareStatement(
            "INSERT INTO "+vsamCatalog+"\\"+FlightCluster+"\\"+FlightMapName+
            " (RS_SERIAL1,RS_SERIAL2,RS_QTY1,RS_QTY2,RS_UPDATE,RS_UPTIME,RS_EMPNO,RS_PRINTFLAG,"+
            "RS_PART_S,RS_PART_IN_A_P,RS_FILLER)"+" VALUES(?,?,?,?,?,?,?,?,?,?,?)");
            //pstmt.setString(1, "12345678901234567890123003");
            pstmt.setString(1, "1234567890");
            pstmt.setString(2,"1234567890123");
            pstmt.setInt(3,00);
            pstmt.setInt(4,003);
            pstmt.setString(5,"151209");
            pstmt.setString(6, "094435");
            pstmt.setString(7,"09932");
            pstmt.setString(8,"P");
            pstmt.setString(9,"Y");
            pstmt.setString(10,"Y");
            pstmt.setString(11," ");
            // Execute the query
            int num = pstmt.executeUpdate();
            System.out.println(num);
            pstmt.close();

            }
            catch (SQLException t)
            {

                System.out.println(t.toString());                       
            } 

        try
        {
        // Get a statement
        java.sql.Statement stmt = jdbcCon.createStatement();
        // Execute the query ...
        java.sql.ResultSet rs = stmt.executeQuery(
        "SELECT * FROM "+vsamCatalog+"\\"+FlightCluster+"\\"+FlightMapName);

        while (rs.next())
        {                                           
        System.out.println(rs.getString("RS_SERIAL1") +  " " + rs.getString("RS_SERIAL2")+  " " + rs.getString("RS_UPTIME")+ " " + rs.getString("RS_UPDATE"));
        }
        rs.close();
        stmt.close();
        }
        catch (SQLException t)
        {

        } 
    }
    catch (Exception e)
    {
        // do something appropriate with the exception, *at least*:
        e.printStackTrace();
    } 

}

}

注意:操作系统为z/VSE

Note: the OS is z/VSE

推荐答案

原始问题的简短答案是KSDS VSAM不是DBMS.

The short answer to your original question is that KSDS VSAM is not a DBMS.

您已经发现,可以定义VSAM文件,以便可以从批处理和从CICS更新它,但是正如@BillWoodger指出的那样,您必须自己序列化更新.

As you have discovered, you can define the VSAM file such that you can update it both from batch and from CICS, but as @BillWoodger points out, you must serialize your updates yourself.

另一种方法是从CICS区域进行所有更新,并让Java应用程序向CICS发送REST或SOAP或MQ消息以请求其更新.这确实需要一个CICS程序来捕获来自Java应用程序的请求并执行更新.

Another approach would be to do all updates from the CICS region, and have your Java application send a REST or SOAP or MQ message to CICS to request its updates. This does require there be a CICS program to catch the requests from the Java application and perform the updates.

这篇关于使用Java JDBC写入VSAM文件时将其锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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