2012-12-12 20 views
1

我試圖對生活在Weblogic 10.3.5中的數據源進行JNDI查找。爲什麼我無法在applet中獲得遠程數據源?

我有以下代碼:

try { 
    //jbInit(); 

    env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); 
    env.put(javax.naming.Context.PROVIDER_URL,"t3://localhost:7001"); 

    try { 
     Context ctx = new InitialContext(env); 
     javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/sandboxDS"); 
     conn = ds.getConnection(); 
    } catch(Exception e){ 
     e.printStackTrace(); 
    } 

    if(conn != null){ 
     System.out.println("Got connection..."); 

     String colDescQuery = 
     "select column1 from my_table where table_name = 'your_table' order by col_order_no"; 
     Statement colDescStmt = conn.createStatement(); 
     ResultSet colDescRS = colDescStmt.executeQuery(colDescQuery); 

     while (colDescRS.next()) { 
     System.out.println(colDescRS.getString(1)); 
     }     

    } else { 
     System.out.println("No connection..."); 
    } 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

當我運行這段代碼作爲一個獨立的Java程序,它完美的作品。連接被找到並且查詢返回預期的結果。

當我在applet中使用相同的代碼並從JDeveloper applet查看器運行它時,它會掛起InitialContext實例化的位置。沒有例外情況發生,它永遠不會返回。

關於這裏發生了什麼的任何想法?我的classpath中有兩個運行的weblogic.jar和wlthint3client.jar。

謝謝...

回答

0

小程序有沙盒限制,使他們不能連接到比他們在那裏下載其他服務器。

確保您的applet也部署到與您的JNDI數據源相同的WebLogic Server。

+0

謝謝。該代碼正在從JDeveloper applet查看器運行,因此沙箱限制不適用。對於真正的部署,我計劃對applet進行簽名。 – Eric

+0

您是否確定JDeveloper不會使用沙盒用於小程序?默認情況下,小程序查看器最近會執行此操作。 –

相關問題