public class Test {
     public static void main(String[] args) {
          DataSource ds = null;
          Context ctx = null;
          Connection myConn = null;
          try {
               /*
                * 获得WebLogic ServerJNDI初始上下文信息
                */
               ctx = getInitialContext();
               /*
                * 建立数据源对象
                */
               ds = (javax.sql.DataSource) ctx.lookup("datasource");
          } catch (Exception e) {
               e.printStackTrace();
          }
     }
     private static Context getInitialContext() throws Exception {
          String url = "t3://localhost:7001";
          String user = "";// 对应的weblogic管理名字
          String password = "";// 密码
          Properties properties = null;
          try {
               properties = new Properties();
               properties.put(Context.INITIAL_CONTEXT_FACTORY,
                         "weblogic.jndi.WLInitialContextFactory");
               properties.put(Context.PROVIDER_URL, url);
               if (user != null) {
                    properties.put(Context.SECURITY_PRINCIPAL, user);
                    properties.put(Context.SECURITY_CREDENTIALS,
                              password == null ? "" : password);
               }
               return new InitialContext(properties);
          } catch (Exception e) {
               throw e;
          }
     }
}