properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic_jndi_WLInitialContextFactory");你看看这样行不

解决方案 »

  1.   

    Cannot instantiate class: weblogic.jndi.WLInitialContextFactory
    不能初始化类...
    weblogic.jar在你的classpath了吗?
      

  2.   

    以下示例供你参考:
    import java.sql.*;
    import javax.naming.*;
    import javax.sql.DataSource;
    import java.util.*;/**
     * <p>Description:数据访问工厂</p>
     * Date:2004.6.21
     *
     */
    public abstract class DBDAOFactory {  public static Connection conn = null;
      public abstract DBDAO createDAO();  //创建连接
      public static DBDAO createDBDAOFactory(String tablename) {
          return new OracleDBDAOFactory(tablename).createDAO();
      }  //添加一个静态方法,该方法的作用是获得WebLogic Server的初始上下文环境以进行JNDI查询
      private static Context getInitialContext() throws Exception {
        //t3代表控制台通信协议,对应WebLogic Server的地址、端口号
        String url = "t3://localhost:7001";
        String user = "weblogic"; //对应WebLogic Server的系统用户名
        String password = "weblogic"; //对应WebLogic Server的口令
        Properties prop = null; //声明属性包对象
        try {
          prop = new Properties();
          prop.put(Context.INITIAL_CONTEXT_FACTORY,
                   "weblogic.jndi.WLInitialContextFactory");
          prop.put(Context.PROVIDER_URL, url); //确定提供命名服务的Weblogic服务器的URL
          if (user != null) {
            prop.put(Context.SECURITY_PRINCIPAL, user); //为认证的目的确定用户(即在Weblogic服务器安全领域定义的用户)的身份。
            prop.put(Context.SECURITY_CREDENTIALS, password);
          }
          return new InitialContext(prop);
        }
        catch (Exception e) {
          throw e;
        }
      }  //一个静态方法,返回一个数据库的连接,这样达到了对数据库连接统一控制的目的
      public static Connection getConnection() {
        Context ctx = null;
        DataSource datasource = null;
        try {
          //获得WebLogic Server JNDI初始上下文信息
          ctx = getInitialContext();
          //建立数据源对象,查找JNDI名字为MyJDBCDataSource的数据源
          datasource = (javax.sql.DataSource) ctx.lookup("MyJDBCDataSource");
          try {
            conn = datasource.getConnection(); //通过数据源对象建立数据连接
          }
          catch (SQLException se) {
            se.printStackTrace();
          }
        }
        catch (Exception ex) {
        }    return conn;
      }  //关闭连接
      public static void cleanup(ResultSet pResultSet,
                                 Statement pStmt,
                                 Connection pConn) throws SQLException {    try {
          if (pResultSet != null) {
            pResultSet.close();
            pResultSet = null;
          }
        }
        catch (SQLException e) {
          throw e;
        }
        finally {
          try {
            if (pStmt != null) {
              pStmt.close();
              pStmt = null;
            }
          }
          catch (SQLException e) {
            throw e;
          }
          finally {
            try {
              if (pConn != null) {
                pConn.close();
                pConn = null;
              }
            }
            catch (SQLException e) {
              throw e;
            }
          }
        }
      }}
      

  3.   

    我刚刚是没有配置好JBuilderX的run,现在配置好了。但是出现了新的异常:
    javax.naming.CommunicationException [Root exception is java.net.ConnectException: t3://localhost:7001: Destination unreachable; nested exception is: 
    java.net.ConnectException: Connection refused: connect; No available router to destination]
    这是什么异常????
      

  4.   

    各位这个问题我也解决了,是WebLogic没有正确的启动。但是又出现了异常:
    Unable to resolve 'test' Resolved
    我的数据源的JNDIName绝对是test,并且发布在了目标域。请问这是为什么?是不是该碰上的异常我都碰上了?倒霉!!!