java—当jcombobox选择netbeans上的sid时,如何让textfield填充正确的主机ip地址

ie3xauqp  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(219)

我很难让tnsname.ora文件执行以下操作:

I managed to get the JComboBox populated with the data from the service_name

My next question is the following:

答。如果在jcombobox上选择了特定的服务名称,那么如何填充正确/适当的主机名(例如127.0.0.3)。
一。我知道这可以使用itemstatechanged(itemevent ie)来完成,并且我可以使它成为一个动作,这样每当选择不同的服务名称时,它就会填充数据。但问题是如何或怎样才能做到以下几点:

If the service_name equals a certain SID

答。然后去填充存储以下内容的文本框:
一。主办
二。港口
三、协议
我有自己的理论如何做到这一点,但不知道如何将其转换为java代码:
如果选择了服务名称
转到上一行(后退4步)填充主机详细信息->将主机数据填充到主机文本框
转到上一行中填充端口的位置->将端口数据填充到端口文本框

public void PopulateTnsNamesDropDownList() {
    Properties prop = new Properties();

    InputStream input2 = null;

    try {
        input2 = new FileInputStream("C:\\folder\\config.properties");

        try {
            prop.load(input2);
        } catch (IOException e) {
            e.printStackTrace();
        }

        String path = null;
        path = prop.getProperty("tnsnames_directory");

        BufferedReader input = new BufferedReader(new FileReader(path));

        List<String> strings = new ArrayList<String>();

        try {
            String line = null;

            try {
                while ((line = input.readLine()) != null) {
                    if (line.contains("(SERVICE_NAME =")) {
                        String service_name = null;
                        service_name = line.replaceAll("SERVICE_NAME = ", "").trim().replaceAll("\\(", "").replaceAll("\\)", "");

                        strings.add(service_name);
                    }
                }
            } catch (IOException e) {
                JOptionPane.showMessageDialog(Workers.this, "Error, configuration properties did not exist or not set correctly." + e.getMessage());
            }
        }

        finally {
            try {
                input.close();
            } catch (IOException e) {
                JOptionPane.showMessageDialog(Workers.this, "Error, configuration properties did not exist or not set correctly." + e.getMessage());
            }
        }
        String[] lineArray = strings.toArray(new String[] {});
        JComboBox comboBox = new JComboBox(lineArray);
        TnsNamesComboBox.setModel(new javax.swing.DefaultComboBoxModel(lineArray));
    } catch (FileNotFoundException e) {
        JOptionPane.showMessageDialog(Workers.this, "Error, configuration properties did not exist or not set correctly." + e.getMessage());
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题