Skip to Content
0
Aug 30, 2018 at 09:19 PM

Can't connect to HANA database inside SCP using Java.

1112 Views

Dears,

I've spent my whole day trying to find out the root cause of an issue, and I truly believe you can help me on it!

I have a Java application which uses Spring and Hibernate to connect to a HANA database. I'm running it inside SCP, and have configured a binding of my application to my database:

This is how I have configured the JNDI lookup inside my application:

Spring configuration file:

@Profile({"dev","qa","prod"})

@Bean@Resource(name = "jdbc/DefaultDB")

public DataSource dataSource() throws GeneralException { 
  try {      
       final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();           dsLookup.setResourceRef(true);      
       DataSource dataSource = dsLookup.getDataSource("java:comp/env/jdbc/DefaultDB");      
       return dataSource;   
      } catch (Exception e) {      
              String errorDetails = "Error loading datasource (dev,qa,prod profile) - " + SpringConfiguration.class.getName();      
               logger.error(errorDetails, e); 
                throw new GeneralException(errorDetails, e);  
 }}

src/webapp/WEB-INF/web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://xmlns.jcp.org/xml/ns/javaee"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"id="WebApp_ID" version="3.1">   

 <resource-ref>        
    <res-ref-name>jdbc/DefaultDB </res-ref-name>        
    <res-type>javax.sql.DataSource </res-type>   
 </resource-ref>

</web-app>

src/main/resources/META_INF/context.xml:

<?xml version="1.0" encoding="UTF-8"?>

<Context  path="">    

<Resource name="jdbc/DefaultDB"auth="Container"type="javax.sql.DataSource"factory="com.sap.jpaas.service.persistence.core.JNDIDataSourceFactory"/>    

<ResourceLink name="jdbc/DefaultDB"global="jdbc/DefaultDB"type="javax.sql.DataSource" />

</Context>

When I try to run it on SCP, i keep getting this error:

org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/DefaultDB'; nested exception is javax.naming.NameNotFoundException: Name [jdbc/DefaultDB] is not bound in this Context. Unable to find [jdbc].

Do someone have some idea of what might be happening? I'm really running out of options here.

Attachments

tp.png (7.2 kB)