1 Reply Latest reply on May 24, 2008 4:22 AM by pepelara

    Dtabase connection Error(Mysql)

    badhikary81

      Hi!
      thanks for reply.My program main part where arise the problem
      String customerNr = request.getParameter("customer_nr");
      if((customerNr != null) && !(customerNr.equals("")))
      {
      try{
      ejb.CustomerFacadeRemote custFacade = lookupCustomerFacadeBean();
      out.println("Customer's info for nr. " + customerNr + ": " + custFacade.getCustomerInfo(
      Integer.parseInt(customerNr)));
      }catch(Exception ex){
      out.println("Customer with nr. " + customerNr +" not found");
      }
      }
      when I enter customer_nr and submit .program show the output Customer with nr. " + customerNr +" not found.
      My program jboss-ds.xml file is
      <?xml version="1.0" encoding="UTF-8"?>
      .Only contain this.
      My program lookupCustomerFacadeBean() is

      private CustomerFacadeRemote lookupCustomerFacadeBean() {
      try {
      return ((ejb.CustomerFacadeRemoteHome) getServiceLocator().getRemoteHome("java:comp/env/CustomerFacadeBean", ejb.CustomerFacadeRemoteHome.class)).create();
      } catch (NamingException ne) {
      java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ne);
      throw new RuntimeException(ne);
      } catch (CreateException ce) {
      java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ce);
      throw new RuntimeException(ce);
      } catch (RemoteException re) {
      java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", re);
      throw new RuntimeException(re);
      }
      }
      please help me.

        • 1. Re:  Dtabase connection Error(Mysql)
          pepelara

          I have set up MySQL as default DataSource (DefaultDS). You can try it.
          I think this is not the question because I guess you are on a BMP Ejb.

          Anyway, what version are you using? I am using 4.2.2 GA and I have no
          any jboss-ds.xml. Can you tell me if it is a BMP and the version of your JBoss.

          By the way, I am observing your code,

          private CustomerFacadeRemote lookupCustomerFacadeBean() {
          try {
          return ((ejb.CustomerFacadeRemoteHome) getServiceLocator().getRemoteHome("java:comp/env/CustomerFacadeBean", ejb.CustomerFacadeRemoteHome.class)).create();

          Try to simplify. This is my client to call to the EJB,

          Properties properties = new Properties();
           properties.put(Context.INITIAL_CONTEXT_FACTORY,
           "org.jnp.interfaces.NamingContextFactory");
           properties.put(Context.PROVIDER_URL, "localhost:1099");
          
           try {
           // Get an initial context
          InitialContext jndiContext = new InitialContext(properties);
           System.out.println("Got context");
          
           // Get a reference to the Bean
           Object ref = jndiContext.lookup("BMPBooks");
           System.out.println("Got reference");
           // Get a reference from this to the Bean's Home interface
           BooksHomeRemote home = (BooksHomeRemote)
           PortableRemoteObject.narrow(ref, BooksHomeRemote.class);
          


          And now I can create the bean (home.create(...))

          I give you the descriptors,

          The ejb-jar.xml,
          <?xml version="1.0" encoding="UTF-8"?>
          <ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
           <description>Your first EJB application </description>
           <display-name>Bookstore Application</display-name>
           <enterprise-beans>
           <entity>
           <ejb-name>BMPBooks</ejb-name>
           <home>es.deusto.ejb.BooksHomeRemote</home>
           <remote>es.deusto.ejb.BooksRemote</remote>
           <ejb-class>es.deusto.ejb.BooksBean</ejb-class>
           <persistence-type>Bean</persistence-type>
           <prim-key-class>java.lang.Integer</prim-key-class>
           <reentrant>false</reentrant>
           <env-entry>
           <env-entry-name>dbUrl</env-entry-name>
           <env-entry-type>java.lang.String</env-entry-type>
           <env-entry-value>jdbc:mysql://localhost:3306/myDB</env-entry-value>
           </env-entry>
           <env-entry>
           <env-entry-name>dbUserName</env-entry-name>
           <env-entry-type>java.lang.String</env-entry-type>
           <env-entry-value>myDbUser</env-entry-value>
           </env-entry>
           <env-entry>
           <env-entry-name>dbPassword</env-entry-name>
           <env-entry-type>java.lang.String</env-entry-type>
           <env-entry-value>myDbPassword</env-entry-value>
           </env-entry>
           </entity>
           </enterprise-beans>
          </ejb-jar>
          


          And the application.xml,
          <?xml version="1.0" encoding="UTF-8"?>
          <application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
           <display-name>MyBookstore</display-name>
           <description>Application description</description>
           <module>
           <ejb>bookstore-ejb.jar</ejb>
           </module>
           <module>
           <java>bookstore-client.jar</java>
           </module>
          </application>
          


          I hope it help you
          Regarding,
          Jose Alvarez de Lara