4 Replies Latest reply on Jan 31, 2006 10:04 PM by z981845

    Problem in getting database connection

    baba79au

      Hi,

      I am using the JBoss App Server, Informix Database.

      I am getting a problem to get the jdbc connection, while my EJB are doing well. When i try to get the database connection from standard java class using this code:

      private Connection getConnection() {
      try {
      //this function returns the initial context
      Context ctx = PbsConfig.getInitialContext();
      DataSource source = (DataSource) ctx.lookup(java:PBSDataSource);
      Connection con = source.getConnection();
      return con;
      } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e.getMessage());
      }
      }

      I am getting this following error:

      javax.naming.NameNotFoundException: PBSDataSource not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:534)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)

      I am using the Informix database and the cofiguration file informix-ds.xml for this is :


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

      <local-tx-datasource>
      <jndi-name>PBSDataSource</jndi-name>
      <connection-url>jdbc:informix-sqli://localhost:1302/mydb:INFORMIXSERVER=adb01</connection-url>
      <driver-class>com.informix.jdbc.IfxDriver</driver-class>
      <user-name>sa</user-name>
      sa
      <min-pool-size>5</min-pool-size>
      <max-pool-size>20</max-pool-size>

      <type-mapping>InformixDB</type-mapping>

      </local-tx-datasource>




      So Please suggest me if i'm missing something in configuration.
      thanks.

        • 1. Re: Problem in getting database connection
          lafr

          If I understood you correct your EntityBeans use the informix datasource without problems and you want to access jboss's datasource from a standalone java app.
          AFAIK this is not possible / allowed. The java: namespace is not accessible from outside the app server.

          • 2. Re: Problem in getting database connection
            fbiaggi

            Hi,
            maybe this can work:

            
             <local-tx-datasource>
             <jndi-name>remotemysql</jndi-name>
             <use-java-context>false</use-java-context>
             <connection-url>jdbc:mysql://localhost:3306/mydb?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=latin1&amp;useServerPrepStmts=false</connection-url>
             <driver-class>com.mysql.jdbc.Driver</driver-class>
             <user-name></user-name>
             <password></password>
             <connection-property name="autoReconnect">true</connection-property>
             <entity-command name="no-select-before-insert"/>
             <prepared-statement-cache-size>1000</prepared-statement-cache-size>
             <max-pool-size>200</max-pool-size>
             <!-- Typemapping for JBoss 4.0 -->
             <metadata>
             <type-mapping>mySQL</type-mapping>
             </metadata>
             </local-tx-datasource>
            


            • 3. Re: Problem in getting database connection
              baba79au

              Hi fbiaggi,
              thank you very much, this config solved my problem. Thanks for your support.

              Regards
              baba S

              • 4. Re: Problem in getting database connection
                z981845

                 

                "lafr" wrote:
                If I understood you correct your EntityBeans use the informix datasource without problems and you want to access jboss's datasource from a standalone java app.
                AFAIK this is not possible / allowed. The java: namespace is not accessible from outside the app server.