1. 执行文件 wljarbuilder.jar

cd E:beawlserver_10.3serverlib

java -jar wljarbuilder.jar

  1. 复制得到的 wlfullclient.jar 到客户端项目中去, 否则无法执行数据源远程操作

相关代码:

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.Properties;


    
    

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.sql.DataSource;


    
    

/**

 * 使用JNDI访问数据源的测试代码.

 */

public class WlsJNDIDataSourceTest

{


    
    

    public WlsJNDIDataSourceTest()

    {

        try

        {

            Properties prop = new Properties();

            prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,

                    "weblogic.jndi.WLInitialContextFactory");

            prop.setProperty(Context.PROVIDER_URL, "t3://localhost:7001");

            InitialContext initial = new InitialContext(prop);

            DataSource dataSource = (DataSource) initial.lookup("jdbc/oracle");

            Connection conn = dataSource.getConnection();


    
    

            Statement statement = conn.createStatement();


    
    

            ResultSet rs = statement

                    .executeQuery("SELECT * FROM T_USER_ENTITY");


    
    

            while (rs.next())

            {

                System.out.println(rs.getString(1));

            }


    
    

            // realease when press a key

            // System.in.read();


    
    

            rs.close();

            statement.close();


    
    

            conn.close();

        } catch (Exception ex)


    
    

            conn.close();

        } catch (Exception ex)

        {

            ex.printStackTrace();

        }

    }


    
    

    public static void main(String[] args)

    {

        new WlsJNDIDataSourceTest();

    }


<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color:</div> </div>

转载请注明:WebLogic Android 博客 » JNDI 访问外部 WebLogic 11 数据源的操作步骤