I'm having problems getting a DataSource to work from a Session Bean. Even after I followed the instructions at this link:
http://help.sap.com/saphelp_nw04/helpdata/en/7d/26e96f1d754408bfd658b6614cb1b6/content.htm
and setup a "Resource Reference" in ejb-jar.xml
<res-ref-name>jdbc/SAPJ2EDB</res-ref-name>
where SAPJ2EDB is of course the 'default' DataSource shown by Visual Administrator.
Here's the code snippet
Connection conn = null; try { InitialContext ctx = new InitialContext(); DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/SAPJ2EDB"); conn = ds.getConnection(); if (conn == null) { throw new SQLException("Connection Failed"); } conn.setAutoCommit(false); } catch (SQLException sex) { sex.printStackTrace(); return null; } catch (NamingException ex) { ex.printStackTrace(); return null; }
What happens is this: no Exception is thrown, but no data is returned by the Bean's business method. In other words, no data displays in my Web Dynpro View. The problem is not my EJB method or my WD View because
[1] When I return a dummy String w/o hitting the database everything displays correctly.
[2] I have pulled the code into a console app and replaced the DataSource with a std JDBC connection; this works as expected
I don't understand because the results are the same no matter what I put into the lookup statement:
ctx.lookup("java:comp/env/jdbc/SAPJ2EDB")
ctx.lookup("jdbc/SAPJ2EDB")
If the lookup is failing, why don't I get an error??