Java TIP (2)

zhaozj2021-02-16  108

(1) Weblogic JNDI Configuration

NOTE: The JNDI Name In WebLogic Is Very Importation. It's NOT A SET for JNDI, But The JNDI Name Which in JNDI SET.

(2) Remember Restart The Weblogic Server WHEN U Change The Weblogic's Configuration, Else, IT Should Be Error When Use This Configuration in JBuilder.

(3) The Steps for Connect Database Through WebLogic:

1) SET DATASOURCE IN WebLogic

2) Get DataSource in Program

3) Connect the datasource

4) Do Sql Operation in Program.

5) Release All

LIKE THIS:

Try {

// Get the initial context information of WebLogic Serverjndi

CTX = GetInitialContext ();

/ / Establish a data source object

DS = (javax.sql.datasource)

/ / Find the JDATASTORE data source via the JNDI context, if you are using JDATASTORE

//ctx.lookup("dsjdataStore ");

/ / Find Oracle9i data sources through the JNDI context

CTX.lookup ("lsidbsource");

.

//establish connection

MyConn = ds.getConnection ();

/ / Establish a statement object

MyStatement = MyConn.createStatement ();

// Establish a result set object

// Establish a JDATASTORE result set object

// myresultset = MyStatement.executeQuery ("Select * from Employee);

// Establish an Oracle9i result set object

// myresultset = MyStatement.executeQuery ("SELECT * from scott.emp");

MyResultSet = MyStatement.executeQuery ("SELECT * from lsi.test");

.

IF (MyStatement! = NULL) {

MyStatement.Close ();

}

IF (MyConn! = null) {

MyConn.close ();

}

转载请注明原文地址:https://www.9cbs.com/read-11151.html

New Post(0)