Find location of oracle_home from java
What would be the best way to find oracle home and tnsnames.ora from java? Actually i am trying to get a list of tns entries and display it in program combobox开发者_开发百科.
There is no some automatic search. If you want Oracle's JDBC driver to use your tns names, you have to define system property (-D) oracle.net.tns_admin=<directory where tnsnames.ora is located>. I recommend setting it up so you can use it and ojdbc will be use it too (if needed)
tnsnames.ora is in ORACLE_HOME/network/admin. Code would be:
String oracleHome = System.getenv("ORACLE_HOME");
if(oracleHome != null){
     String tnsFilename = oracleHome + File.separatorChar + 
                       "network" + File.separatorChar + 
                       "admin" + File.separatorChar + 
                       "tnsnames.ora";
}
If you've ORACLE_HOME set as an envinroment variable then you can use System.getenv("ORACLE_HOME"); to access it. 
See javadoc.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论