OracleConnectionStringParser

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class OracleConnectionStringParser {

public static void parseConnectionString(String connectionString) {

String regex = "\\(HOST =([^)]+)\\)\\(PORT =([^)]+)\\)";

Pattern pattern = Pattern.compile(regex);

Matcher matcher = pattern.matcher(connectionString);

while (matcher.find()) {

String ip = matcher.group(1).trim();

int port = Integer.parseInt(matcher.group(2).trim());

System.out.println("IP Address: " + ip + ", Port: " + port);

}

}

public static void main(String[] args) {

String connectionString = "User ID=111;Password=222;Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST =10.1.1.1)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST =10.1.1.2)(PORT = 1521)))(CONNECT_DATA =(SERVER = 123)(SERVICE_NAME = 333)(FAILOVER_MODE =(TYPE = SESSION)(METHOD =BASIC)(RETRIES = 2)(DELAY = 1))))";

parseConnectionString(connectionString);

}

}

相关推荐
黄油饼卷咖喱鸡就味增汤拌孜然羊肉炒饭13 分钟前
SpringBoot如何实现缓存预热?
java·spring boot·spring·缓存·程序员
暮湫29 分钟前
泛型(2)
java
超爱吃士力架34 分钟前
邀请逻辑
java·linux·后端
南宫生39 分钟前
力扣-图论-17【算法学习day.67】
java·学习·算法·leetcode·图论
转码的小石1 小时前
12/21java基础
java
李小白661 小时前
Spring MVC(上)
java·spring·mvc
GoodStudyAndDayDayUp1 小时前
IDEA能够从mapper跳转到xml的插件
xml·java·intellij-idea
装不满的克莱因瓶2 小时前
【Redis经典面试题六】Redis的持久化机制是怎样的?
java·数据库·redis·持久化·aof·rdb
n北斗2 小时前
常用类晨考day15
java
骇客野人2 小时前
【JAVA】JAVA接口公共返回体ResponseData封装
java·开发语言