cancel
Showing results for 
Search instead for 
Did you mean: 

Oracle connection using DataSource

Former Member
0 Kudos

Hi all,

I'm trying to connect Oracle DB using dataSource from an EJB:

try {

InitialContext ctx = new InitialContext();

DataSource ds = (DataSource) ctx.lookup("java:comp/env/ejb/ORDINE_MODELLO_POOL");

Connection con = ds.getConnection();

String query = "select ordine_modello_sq.nextval from dual";

Statement stmt = con.createStatement();

try {

ResultSet rs = stmt.executeQuery(query);

try {

while ( rs.next() ) {

//Insert the sequence value

int prog_ordine_int = rs.getInt(1);

prog_ordine_seq = new Integer(prog_ordine_int);

}

} finally {

rs.close();

}

} finally {

stmt.close();

}

}catch (Exception e) {

e.printStackTrace();

}

I have this error:

com.sap.engine.services.jndi.persistent.exceptions.NamingException: Exception during lookup operation of object with name ejbContexts/sap.com/ModelloApplication/MySessionBean/java:comp/env/jdbc/ORDINE_MODELLO_POOL, cannot resolve object reference. [Root exception is com.sap.engine.services.connector.exceptions.BaseResourceException: ConnectionFactory "jdbc/ORDINE_MODELLO_POOL" does not exist. Possible reasons: the connector in which ConnectionFactory "jdbc/ORDINE_MODELLO_POOL" is defined is not deployed or not started.]

What I can do to solve the problem? Thanks to all.

Vito

Accepted Solutions (1)

Accepted Solutions (1)

detlev_beutner
Active Contributor
0 Kudos

Hi,

have the answers been of any value for you? If yes, please consider rewarding points for helpful answers! Thanks in avance!

Best regards

Detlev

Former Member
0 Kudos

Detlev,

the problem is yet an open point, indeed is not possible to go with a JDBC connection. The server has an Unix OS and probabily this cause some problems.

I solved the problem using QL query in entity.... but I would like to know why JDBC doesn't run!!!

Vito Palasciano

former_member184385
Active Participant
0 Kudos

Hi Vito,

could you please tell us

- what driver jars you are using?

- what oracle db you are attempting to access to (version)?

- what your DS config looks like, passing the exported DS xml along?

- if, after definition, you did test the DS?

I'm really convinced, making a DS fly, even on *nix, can be done. Let's give it another try!

Regards

Gregor

htammen
Active Contributor
0 Kudos

Hi Vito,

usually you access your datasources via

java:comp/env/jdbc/.

You can also try it without java:comp/env/. This also work because the jdbc context is located directly under the root of the jndi tree.

One of these things should help.

Regards

Helmut

Former Member
0 Kudos

Thanx Helmut,

your help has been very helpful. I solved the problem writing the lookup without java:comp/env/

This sounds right to the system.

Vito

Answers (4)

Answers (4)

Former Member
0 Kudos

hi Vito,

See this links

Hope this helps you

Regards

Rohit

Former Member
0 Kudos

Please check ur JNDI Registry usinh Visaul Admin Tool, It lists all the objects available in the JNDI tree.

J2E>Server>Services-->JNDI Registry

Former Member
0 Kudos

Please check ur JNDI Registry using Visual Admin Tool, It lists all the objects available in the JNDI tree.

J2E>Server>Services-->JNDI Registry

Former Member
0 Kudos

Pls. Recheck whether the datasource is deployed properly and it is referring proper connection pool.

Instead of testing the connection pool through code, check connection pool through server whether configuration is correct. It should give ok.

Hope this will help you.

Regards,

Mani

detlev_beutner
Active Contributor
0 Kudos

Hi Vito,

as already written last night:

> java:comp/env/<b>ejb</b>/ORDINE_MODELLO_POOL

?!?! Is this a typo?!

Hope it helps

Detlev

Former Member
0 Kudos

Hi Vito,

the error is in the lookup of the datasource

<b>DataSource ds = (DataSource) ctx.lookup("java:comp/env/ejb/ORDINE_MODELLO_POOL");</b>

Though exactly what the problem is I can not tell you as I am not familiar with your application. You are either referencing the datasource wrong or the the service is not active or deployed.

You could try a direct JDBC connection.

regards,

Dion