web服务器 weblogic
数据库: oracle816
在weblogic配置好了connection pool 和datasource  在程序中调用的时候抛出如下异常:java.sql.SQLException: Pool connect failed : java.lang.SecurityException: [Secur
ity:090398]Invalid Subject: principals=[system]
        at weblogic.jdbc.common.internal.JDBCUtil.wrapAndThrowResourceException(
JDBCUtil.java:160)
        at weblogic.jdbc.pool.Driver.connect(Driver.java:156)
        at weblogic.jdbc.jts.Driver.getNonTxConnection(Driver.java:444)
        at weblogic.jdbc.jts.Driver.connect(Driver.java:138)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSour
ce.java:305)
        at com.hhzskj.dzsb.db.ConnectionFactory.getConnection(ConnectionFactory.
java:86)连接池的程序如下:
××××××××××××××××××××××××××××××××××××××××
private  static void getInitContext()throws NamingException{
        Hashtable ht = new Hashtable();
        if(factorySingleton == null){
            factorySingleton = new ConnectionFactory();
        }
        ht.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
        ht.put("java.naming.provider.url",rdp.getUrl());
        if(rdp.getUser() != null){
            ht.put("java.naming.security.principal",rdp.getUser());
            ht.put("java.naming.security.credentials",rdp.getPwd());
        }
        initCtx = new InitialContext(ht);
    }
    /**
     *
     * @return Connection
     * @throws NamingException
     * @throws SQLException
     */
    public static Connection getConnection()throws NamingException, SQLException{
        if(dataSource == null){
            getInitContext();
            Object obj = initCtx.lookup(rdp.getDataSource());
            dataSource = (DataSource)PortableRemoteObject.narrow( obj, getClass("javax.sql.DataSource"));
        }
        return dataSource.getConnection();
    }
××××××××××××××××××××××××××××××××××××××××如果改为直接连接的话就不会出现上面的情况。 希望高手来解决。3ks

解决方案 »

  1.   

    Please note that BEA does recomment using JAAS in stead of JNDI to associate a user with context. I would believe what you are facing here is a bug / design flaw
      

  2.   

    你是不是用system用户名登录的?好像是权限不够,用sys试试
      

  3.   

    就没人知道么???? 郁闷>>>>>
      

  4.   

    这样试试吧:因为你的getInitContex()没有返回类型,不能返回,下面就不能get了,private  static Context getInitContext()throws NamingException{
            Hashtable ht = new Hashtable();
            if(factorySingleton == null){
                factorySingleton = new ConnectionFactory();
            }
            ht.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
            ht.put("java.naming.provider.url",rdp.getUrl());
            if(rdp.getUser() != null){
                ht.put("java.naming.security.principal",rdp.getUser());
                ht.put("java.naming.security.credentials",rdp.getPwd());
            }
            initCtx = new InitialContext(ht);//如果不改的话,initCtx的作用域设置是否有问题
            return initCtx;
        }
        /**
         *
         * @return Connection
         * @throws NamingException
         * @throws SQLException
         */
        public static Connection getConnection()throws NamingException, SQLException{
            if(dataSource == null){
                getInitContext();
                Object obj = initCtx.lookup(rdp.getDataSource());
                dataSource = (DataSource)PortableRemoteObject.narrow( obj, getClass("javax.sql.DataSource"));
            }
            return dataSource.getConnection();
        }
      

  5.   

    initCtx 我设置的全局变量!
      

  6.   

    试一下把WEBLOGIC中的;INITIAL CAPACITY改大一点,可能是连接数量太小
      

  7.   

    import weblogic.jndi.WLInitialContextFactory   这个东西.
      

  8.   

    ht.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
            ht.put("java.naming.provider.url",rdp.getUrl());
            if(rdp.getUser() != null){
                ht.put("java.naming.security.principal",rdp.getUser());
                ht.put("java.naming.security.credentials",rdp.getPwd());
            }改为
     ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
            ht.put(Context.PROVIDER_URL,rdp.getUrl());
            if(rdp.getUser() != null){
                ht.put(Context.SECURITY_PRINCIPAL,rdp.getUser());
                ht.put(Context.SECURITY_CREDENTIALS,rdp.getPwd());
            }
      

  9.   

    你是不是没有修改startWLS.bat文件的path 和 CALSSPATH 部分
      

  10.   

    取完DataSource再取Connection试试,不要取完Context不关闭. private static String INITIAL_CONTEXT_FACTORY="weblogic.jndi.WLInitialContextFactory";
    private static String PROVIDER_URL="t3://localhost:7001";
    private static String JNDI_NAME="oracleds";
    private static DataSource mDefaultDsOracle=null;
    Context ctx = null;
    Hashtable ht = new Hashtable();
    ht.put(Context.INITIAL_CONTEXT_FACTORY,INITIAL_CONTEXT_FACTORY);
    ht.put(Context.PROVIDER_URL,PROVIDER_URL);
    try
    {
    ctx = new InitialContext(ht);
    mDefaultDsOracle=(javax.sql.DataSource)ctx.lookup (OracleDataSource.JNDI_NAME);
    }
    finally{
    try 
    {
    ctx.close();
    }
    catch(Exception e)
    {
    }
    }
      

  11.   

    再用mDefaultDsOracle.getConnection(username, password);获得连接