简体   繁体   中英

How to pass encryption related properties from tomcat's context.xml for jdbc connection in java?

We have an application developed in struts2. The application server used is Weblogic. We are using Sybase ASE database. We are using plain JDBC to connect to database.

Recently we turned the encryption on in weblogic server. So we added 3 properties

key="ENCRYPT_PASSWORD" value="true"

key="JCE_PROVIDER_CLASS" value="org.bouncycastle.jce.provider.BouncyCastleProvider"

key="RETRY_WITH_NO_ENCRYPTION" value="true" 

The weblogic server is used in PROD environment. In weblogic, it is working fine. But we do local development using tomcat 7.0. In tomcat, we are using context.xml with following tags.

<Resource name="CONN.DS" auth="Container"      
   type="javax.sql.DataSource" 
   username="abc" 
   password="dfg"      
     driverClassName="com.sybase.jdbc4.jdbc.SybDriver"    
      url="jdbc:sybase:Tds:xyz:1234/DbName"      
        maxActive="10" maxIdle="4"/>

To get connection in java, we use below code,

javax.sql.Datasource ds = null;
try{


            Context initContext = new InitialContext();
            Context envContext = (Context) initContext.lookup("java:/comp/env");
              ds = (DataSource) envContext.lookup("CONN.DS");

}catch(Exception e){
e.printStackTrace();
}

return ds.getConnection();

Actually in weblogic, by adding above 3 properties, it is working fine. But in tomcat, we use context.xml. So how can we pass above three properties through context.xml while taking a connection in eclipse and tomcat?

At present, at line ' ds.getConnection() ', it is giving error :

'An exception occurred: org.apache.tomcat.dbcp.dbcp.SQLNestedException'

    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)

Please advise.

Use the following connection string:

jdbc:sybase:Tds:xyz:1234/DbName?ENCRYPT_PASSWORD=true&JCE_PROVIDER_CLASS=org.bouncycastle.jce.provider.BouncyCastleProvider&RETRY_WITH_NO_ENCRYPTION=true

Also, check http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc39001.0700/html/prjdbc0700/X32549.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM