weblogic下获取数据库连接

    技术2025-11-02  31

    今天是真的玩了一天,再 不干点什么就崩溃了。。。

    趁还没有忘,赶紧写下来吧。。

    -------------------------------------------------------------------------

    //1,初始化服务器上下文

    //1.1设置url

    String url = "t3://localhost:7001";//t3是eba公司特定的表示,同http协议,只是名字不同,用来区别一下的。7001是端口,

                  //同tomcat的8080

    //1.2设置dirver

    String driver = "weblogic.jndi.WLInitialContextFactory";

     

    //1.3把连接weblogic服务器的信息存入properties容器

    Properties p = new Properties();

    p.put(Context.PROVIDER_URL,url);

    p.put(Context.INITIAL_CONTEXT_FOCTORY,driver);

    //1.4把properties对象作为参数

    Context context = new Context(p);

    //2、获取数据源

    DataSource ds = (DataSource)context.lookup("jndi名字");

    //3、返回连接

    return ds.getConnection();

     

    --------------------------------------------------------------------------------------------------------

    2010年9月6日 17:27:21

    By:Frank

    最新回复(0)