Documentation

Trace:

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
jvx:server:security:db_jndi [2019/03/14 10:53]
admin created
jvx:server:security:db_jndi [2020/06/15 11:09] (current)
cduncan Edited for English grammar (capitalization, punctuation, correct verb conjugation)
Line 1: Line 1:
 ~~NOTRANS~~ ~~NOTRANS~~
-~~Title: ​DB Connection via JNDI~~+~~Title: ​Database ​Connection via JNDI~~ 
 + 
 +If you use the [[jvx:​server:​security:​dbsecman|DBSecurityManager]] for authentication,​ or if you use a database in your application,​ the [[jvx:​server:​storage:​datasourcehandler_dbcredentials|configuration]] is in your applications config.xml. 
 + 
 +The configuration is plain xml, and it's possible to [[jvx:​server:​security:​config_encrypt|use encryption]]. It's also possible to read the [[jvx:​common:​setup:​zones|configuration via JNDI]]. 
 + 
 +Another option is to use JNDI to create a database connection. In this case, you should set the JDBC URL to something like this: 
 + 
 +<file xml config.xml>​ 
 +<​application>​ 
 +  ... 
 +  <​securitymanager>​ 
 +    <​class>​com.sibvisions.rad.server.security.DBSecurityManager</​class>​ 
 +    <​database>​ 
 +      <​url>​java:/​comp/​env/​jvx/​myapp/​config/​db</​url>​ 
 +    </​database>​ 
 +  </​securitymanager>​ 
 +  ... 
 +</​application>​ 
 +</​file>​ 
 + 
 +The JNDI resource can be an instance of DBAccess, IConnectionPool,​ java.sql.Connection or javax.sql.DataSource. 
 + 
 +The application code, e.g., in your Session LCO: 
 + 
 +<file java> 
 +protected DBAccess getDBAccess() throws Exception 
 +
 +    DBAccess dba = (DBAccess)get("​dBAccess"​);​ 
 + 
 +    if (dba == null) 
 +    { 
 +        DBCredentials dbcred = DBSecurityManager.getCredentials(SessionContext.getCurrentSessionConfig());​ 
 + 
 +        //no credentials -> no database access possible (should not happen, only if configuration is not finished) 
 +        if (dbcred != null) 
 +        { 
 +            dba = DBAccess.getDBAccess(dbcred);​ 
 +            dba.open();​ 
 + 
 +            put("​dBAccess",​ dba); 
 +        } 
 +    } 
 + 
 +    return dba; 
 +
 +</​file>​ 
 +will work without changes.
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information