oracle data source using weblogic

Keywords: Weblogic Java Database SQL

1. Generate the wlfullclient.jar required by the data source


wlfullclient.jar generation method

Enter weblogic's installation directory


For example

E:\tools\weblogic\wls12213\wlserver\server\libĀ 

Operation

java -jar wljarbuilder.jar


You can generate the wlfullclient.jar file



2. weblogic configuration data source


Basically the next step along the way. Fill in the basic information of the database.




If the test is successful, the configuration is normal.


3. Modification of project configuration


Only the ways spring projects want to change are listed here.

Modify spring-context.xml to comment out the original data source's

Add the following comments

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" >
<property name="jndiName">
<value>bgc-web-test</value>
</property>
<property name="resourceRef">
<value>true</value>
</property>
<property name="jndiEnvironment">
<props>
<prop key="java.naming.provider.url">t3://127.0.0.1:7001</prop>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
</props>
</property>
</bean>














4. Deployment project


Operation steps

Deployment = = > installation = = > select war package = = > next = = >


5. Verify whether the data source is correct by other means


import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
* @author: pnunu
* @Date: 2020/4/27 16:03
* @description:
*/




public class DatabaseConnection {
public static void main(String[] args) throws Exception {
System.out.println(getConnection());
}
//Factory class needed to initialize context
private final static String INITIAL_CONTEXT_FACTORY = "weblogic.jndi.WLInitialContextFactory";
//Access address of WebLogic Server
private final static String PROVIDER_URL = "t3://127.0.0.1:7001";
//JNDI data source name in WebLogic Server
private final static String ORACLE_JNDI_NAME = "jdni-name";


//Stores data sources taken from JNDI containers
private static DataSource dsOracle = null;

static {
try {
//Initialize JNDI context information for WebLogic Server
Context context = getInitialContext();
//Get data source object
dsOracle = (DataSource) context.lookup(ORACLE_JNDI_NAME);
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* MethodName: getInitialContext
* Description: Get WebLogic ServerJNDI initial context information
*
* @return
* @throws Exception
*/






private static Context getInitialContext() throws Exception {
Properties properties = new Properties();
//Specify factory class
properties.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
//Specify server access address
properties.put(Context.PROVIDER_URL, PROVIDER_URL);
return new InitialContext(properties);
}

/**
* MethodName: getOracleConnection
* Description: Get Oracle database connection
*
* @return
* @throws SQLException
*/






public static Connection getConnection() throws SQLException {
return dsOracle.getConnection();
}


/**
* MethodName: CloseConnection
* Description: Close database connection
*
* @return
* @throws SQLException
*/






public static void Close() throws SQLException {
if (dsOracle != null) {
dsOracle.getConnection().close();
}
}
}

























































Posted by Sonic_Rage on Tue, 28 Apr 2020 08:44:21 -0700