我有一个要求,我需要将每个单独的目标连接到数据源。如果 datsource 有两个目标,那么我需要一个一个连接到两个目标。
我正在使用以下代码进行数据源连接。需要知道如何连接到数据源的单个目标
public class ConnectWLSDataSource {
public static void main(String[] args) {
Connection conn;
Statement stmt;
ResultSet rs;
String str1;
try {
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, “weblogic.jndi.WLInitialContextFactory”);
prop.put(Context.PROVIDER_URL, “t3://HOST_NAME:PORT_NUMBER”);
Context ctx = new InitialContext(prop);
Object obj = ctx.lookup(“DATA_SOURCE_NAME”); // java:comp/env/CPDS
System.out.println(“Data Source Found….”);
DataSource ds = (DataSource) obj;
conn = ds.getConnection();
System.out.println(“Data Source User Name::”+conn.getMetaData().getUserName());
stmt = conn.createStatement();
String query = “select 1 from dual”;
System.out.println(“Query ” + query);
rs = stmt.executeQuery(query);
if (rs != null) {
System.out.println(“Some Data Found in Query”);
} else {
System.out.println(“No Data Found in Query”);
}
ctx.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}