2017-02-19 89 views
0

我有:如何從Jboss連接Oracle數據庫並在JDNI中註冊該連接?

public Connection getConnection() throws NamingException { 

    Connection cnn = null; 

    try { 
     InitialContext init = new InitialContext(); 
     DataSource ds = (DataSource) init.lookup("java:/inventario"); 

     try { 
      cnn = ds.getConnection(); 
     } catch(SQLException ex) { 
      System.out.println("ERROR GETTING CONNECTION: "+ex.getMessage()); 
     } 

    } catch(NamingException ne) { 
     System.out.println("ERROR connect method: "+ne.getMessage()); 
    } 
    return cnn; 
} 

並執行測試連接:「錯誤連接方法:需要環境或系統屬性指定的類名,或者作爲一個小程序參數,或在應用程序的資源文件:java.naming .factory.initial」

Jboss的配置JDNI的照片: enter image description here

+0

標題使現在更清晰 – aholbreich

回答

0

上面的代碼返回連接successfully.Check與server.Sample wildfly配置您的JNDI配置如下

<datasource jta="false" jndi-name="java:/MSSQLDS" pool-name="MSSQLDS" enabled="true" use-java-context="true"> 
        <connection-url>jdbc:oracle:thin:@192.168.xx.xxx:1521/xxx.SERVER</connection-url> 
        <driver>oracle</driver> 
        <pool> 
         <min-pool-size>1</min-pool-size> 
         <max-pool-size>5000</max-pool-size> 
         <prefill>true</prefill> 
        </pool> 
        <security> 
         <user-name>xxxx</user-name> 
         <password>xxxx</password> 
        </security> 
       </datasource>