4 Replies Latest reply on Jul 3, 2013 2:44 PM by tareq_zaman

    Need help accessing a jdbc datasource inside ejb on jboss 7.1.1

    tareq_zaman

      Hi,

       

       

      I would appreciate any help on this. I have tried so many ways but no success yet. I am trying to test a datasource inside an session ejb in JBoss AS 7.1.1.Final. Using MS SQL server.

       

       

       

       

      Getting name not found exception, here is the stack trace. Please note in the code I am using the full JNDI name as java:jboss/datasources/ezsystemDS.

       

       

      19:20:57,293 ERROR [stderr] (EJB default - 1) javax.naming.NameNotFoundException: jboss/datasources/ezsystemDS -- service jboss.naming.context.java.jboss.exported.jboss.datasources.ezsystemDS

       

       

      19:20:57,306 ERROR [stderr] (EJB default - 1)           at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)

       

       

      19:20:57,317 ERROR [stderr] (EJB default - 1)           at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)

       

       

      19:20:57,325 ERROR [stderr] (EJB default - 1)           at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)

       

       

      19:20:57,332 ERROR [stderr] (EJB default - 1)           at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)

       

       

      19:20:57,337 ERROR [stderr] (EJB default - 1)           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

       

       

      19:20:57,341 ERROR [stderr] (EJB default - 1)           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

       

       

      19:20:57,344 ERROR [stderr] (EJB default - 1)           at java.lang.Thread.run(Thread.java:724)

       

       

      19:20:57,646 INFO  [org.jboss.as.naming] (Remoting "sc1-mis99" task-3) JBAS011806: Channel end notification received, closing channel Channel ID 5643bfb0 (inbound) of Remoting connection 0148380c to null

       

       

       

       

      When Jboss starts I can see datasources are bound correctly. Also verified that from JBOSS console naming tree view.

       

       

      [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-14) JBAS010400: Bound data source [java:jboss/datasources/ezsystemSeqDS]

      19:15:45,643 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]

      19:15:45,643 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-11) JBAS010400: Bound data source [java:jboss/datasources/ezsystemDS]

      19:15:45,947 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990

      19:15:45,948 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.1.Final

       

       

       

       

      Here is my ejb code

       

       

       

       

                 public String echo(String input){

                              try {

                                              InitialContext ctx = new InitialContext();

                                              DataSource datasrc =  (DataSource)ctx.lookup("java:jboss/datasources/ezsystemDS");

                                              if(datasrc != null) {

                                                        Connection con = datasrc.getConnection();

                                                        con.close();

                                              }

       

                                    } catch (Exception e) {

                                              // TODO Auto-generated catch block

                                              String x = e.getMessage();

                                              e.printStackTrace();

                                    }

                              return "Echoing back " + input ;

          }

       

       

       

      Data sources are configured in module.xml and created using admin console. Thanks.