Binding a DataSource to JNDI

I am trying to use MockRunner's mock DataSources with Weblogic 8.5. I need to bind the DataSource to Weblogic's JNDI to make it available to the application:
MockDataSource ds;
context.rebind("MyDataSource", ds);
But rebind() throws this exception:
testMain(com.demo.tests.jdbc.Mock)javax.naming.NamingException: Unhandled exception in rebind() [Root exception is java.lang.IllegalArgumentException: Object must be a CORBA object: com.mockrunner.mock.jdbc.MockDataSource@7f4ec]
     at weblogic.corba.j2ee.naming.Utils.wrapNamingException(Utils.java:81)
     at weblogic.corba.j2ee.naming.ContextImpl.rebind(ContextImpl.java:340)
     at weblogic.corba.j2ee.naming.ContextImpl.rebind(ContextImpl.java:300)
     at javax.naming.InitialContext.rebind(Unknown Source)
Strangely binding <i>java.lang.String</i>s do work.
I have also tried to bind <i>org.apache.commons.dbcp.PoolingDataSource</i>, and it fails with the same error as with <i>MockDataSource</i>.

Here is the whole piece of code. I need the program to be a standalone Java program. wlclient.jar is in the classpath.
It works when binding strings and looking up existing objects registered to JNDI.
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import com.mockrunner.mock.jdbc.JDBCMockObjectFactory;
import com.mockrunner.mock.jdbc.MockDataSource;
JDBCMockObjectFactory factory = getJDBCMockObjectFactory();
MockDataSource ds = factory.getMockDataSource();
Properties env = new Properties();
env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
env.put( Context.PROVIDER_URL, "t3://localhost:7001" );
InitialContext context = new InitialContext(env);
context.rebind("MockDataSource", ds);

Similar Messages

  • Datasource via JNDI vs Driver Manager

    I am really desperate to use Datasource for connectivity to Oracle (rather than using the driver manager) in my little J2EE app (no EJB) on IBM WSAD 5.0.
    I have some example using DB2 datasource via JNDI.
    I replaced the properties with my Oracle database parameters.
    as below
    userid=scott
    password=tiger
    url=jdbc:oracle:thin:@localhost:1521:library
    driver=oracle.jdbc.OracleDriver
    lookupName=jdbc/library
    database=library
    There is an object "DB2DataSource" coming from package COM.ibm.db2.jdbc.DB2DataSource in the example code "CreateDatasource.java" I am using to create the data source.
    I have added JNDI.jar(from oracle), Naming.jar(from WSAD home), nasmingClient.jar(from WSAD home) in to the project.
    By looking at Oracle manual we need import com.evermind.sql.DriverManagerDataSource; and
    com.evermind.server to get initialContext.
    But compiler cant find them.
    Can anyone tell me what is the equivalent in Oracle?
    Thanks
    Mei

    Hold on.
    This is what I think. There will be others here who might be able to build to this and provide you the solution.
    All that you need to do is
    1. Add the Oracle driver to the WebSphere classpath.
    2. Use the Admin Console / WSAD screens to create a JDBC Driver for the Oracle Driver.
    3. Create a datasource within this driver. There is step-by-step documentation on how to do this.
    4. Specify a JNDI name for the datasource.
    5. Lookup the DataSource and cast it to a DataSource object.
    6. Call getConnection method to get a connection.
    Your coding portion is only steps 5 and 6 above.
    Steps 1 through 4 needs to happen in the Admin Console / WSAD tool. I have done it in both the places before and it is a fairly straightforward process. You do not need any of the jars that you are mentioning below or need to do anything special.
    Vijay

  • J2SE and binding Datasource to JNDI

    Hi all,
    I am trying to create a ODBC-Bridge datasource as per :http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/bridge.html
    I get the initailContect not defined with the following code
    InitialContext ic = new InitialContext();
    ic.bind("jdbc/OdbcDB1",ds);
    so tried adding this :
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");
    Context ctx = new InitialContext(env);
    This also produces an error as LDAP not running i guess??
    I do not understand the initial context, and am not sure the type i should use (LDAP / DNS / CORBA) etc.
    I guess when running a web or J2EE the JNDI is already running and the initial contect is already setup?

    Here is the whole piece of code. I need the program to be a standalone Java program. wlclient.jar is in the classpath.
    It works when binding strings and looking up existing objects registered to JNDI.
    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import com.mockrunner.mock.jdbc.JDBCMockObjectFactory;
    import com.mockrunner.mock.jdbc.MockDataSource;
    JDBCMockObjectFactory factory = getJDBCMockObjectFactory();
    MockDataSource ds = factory.getMockDataSource();
    Properties env = new Properties();
    env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
    env.put( Context.PROVIDER_URL, "t3://localhost:7001" );
    InitialContext context = new InitialContext(env);
    context.rebind("MockDataSource", ds);

  • Datasource and JNDI binding

    Hi
    I'm a beginner in JNDI
    i'm used to connect the Oracle DB using JDBC ,
    now i want to use the JNDI to get a connection pooling
    i've read alot of Documentation about this field and i need to know how to set the LookUp Name to my database
    thank you

    I am not sure how to add configuration in Oracle App Server. But this how you have to do.
    Create a connection object in the app server in the name jdbc/Test . (jdbc/Test is the name of the connection which will be used to get refernece from the JNDI). In the App server you have to create the connection with you userid, password and URL for the connection.
    URL - jdbc:oracle:thin:@servername:1521:databasename
    You may need to have the connection from EJB or may be from the JSP or bean class. If the connection is required in EJB, then EJB container will get the reference. For JSP or Bean the web container will get the reference. You need to make specific entries in ejb-jar.xml and oracle-ejb-jar.xml (I hope there will be file in this name. Beacause for me I have sun-ejb-jar.xml for Sun App server.) for EJB container and in web.xml and oracle-web.xml for web container.
    Here are the entries for web Container -
    In web.xml put this entry -
    <resource-ref>
    <res-ref-name>jdbc/Test</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    In oracle-web.xml put this entry -
    <resource-ref>
    <res-ref-name>jdbc/asta</res-ref-name>
    <jndi-name>jdbc/asta</jndi-name>
    </resource-ref>
    Here is how you will get the connection -
    Context ctx = new InitialContext();
    DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/Test");
    Connection conn = ds.getConnection();
    Thanks

  • How to Configure the Datasource In JNDI and access it through Java Code

    I have declared under web.xml
    <resource-ref>
          <res-ref-name>MSDataSource</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
          <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    Under Jrun-resource.xml
    <data-source>
                <dbname>xxxxxxx</dbname>
                <driver>macromedia.jdbc.sqlserver.SQLServerDriver</driver>
                <url>jdbc:macromedia:sqlserver://xxx.xxx.xx.xx:1433;databaseName=xxxxxxx</url>
                <username>xxxxxxxx</username>
                <password>xxxxxxxxx</password>
                <encrypted>false</encrypted>
                <encryption-class>jrun.security.JRunCrypterForTwofish</encryption-class>
                <native-results>true</native-results>
                <remove-on-exceptions>true</remove-on-exceptions>
                <pool-statements>false</pool-statements>
                <initial-connections>1</initial-connections>
                <connection-timeout>1200</connection-timeout>
                <transaction-timeout>20</transaction-timeout>
                <cache-enabled>false</cache-enabled>
                <cache-size>5</cache-size>
                <cache-refresh-interval>30</cache-refresh-interval>
                <jndi-name>MSDataSource</jndi-name>
                <poolname>Pool</poolname>
                <minimum-size>0</minimum-size>
                <maximum-size>2147483647</maximum-size>
                <user-timeout>20</user-timeout>
                <skimmer-frequency>420</skimmer-frequency>
                <shrink-by>5</shrink-by>
                <maximum-soft>true</maximum-soft>
                <debugging>false</debugging>
                <disable-pooling>false</disable-pooling>
                <isolation-level>READ_UNCOMMITTED</isolation-level>
                <description/>
         </data-source>
    Under jrun-web.xml
    <resource-ref>
          <res-ref-name>MSDataSource</res-ref-name>
          <jndi-name>MSDataSource</jndi-name>
    </resource-ref>  
    Java Code
    String dsndb="java:comp/env/MSDataSource";
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,"jrun.naming.JRunContextFactory");
    p.put(Context.PROVIDER_URL, "localhost:2932");
    InitialContext context=new InitialContext(p);
    System.out.println(context.getEnvironment());
    DataSource ds=(DataSource)context.lookup(dsndb);
    ds.getConnection();
    System.out.println(ds.getConnection().toString());
    Error is
    {java.naming.provider.url=localhost:2932, java.naming.factory.initial=jrun.naming.JRunContextFactory}
    Exception in thread "main" javax.naming.NameNotFoundException: No such binding: MSDataSource
        at jrun.naming.ContextManager.getBinding(ContextManager.java:680)
        at jrun.naming.ContextManager.getBinding(ContextManager.java:686)
        at jrun.naming.ContextManager.getObject(ContextManager.java:690)
        at jrun.naming.ContextManager.lookup(ContextManager.java:463)
        at jrun.naming.JRunNamingContext.lookup(JRunNamingContext.java:501)
        at jrun.naming.JRunNamingContext.lookup(JRunNamingContext.java:644)
        at jrun.naming.JRunNamingContext.lookup(JRunNamingContext.java:470)
        at javax.naming.InitialContext.lookup(Unknown Source)
        at Controller.DBManager.getConnection(DBManager.java:29)
        at Controller.DBManager.main(DBManager.java:42)
    Please help me .
    Thanks in advance

    Also, try to log the username/password in your authenticator, just to be sure that credentials changeGood piece of advice, michael. Worth of it. When I changed the credentials manually, it worked correctly,but from the application, when I logout from 'a', 'a' and log in to 'b', 'b', I got a valuable information.
    I tried debugging like given below for checking from the application.
    class MyAuthenticator extends Authenticator {
        protected PasswordAuthentication getPasswordAuthentication() {
             System.out.println("userrrrrrrrr"+UtilsHTTPS.username);
             System.out.println("pwdddddddddd"+UtilsHTTPS.password);
      .........................................The information I got while debugging from the application was, the username and password does not get printed. It implies that, Authenticator.setDefault(new MyAuthenticator()); does not work as desired ie; even on calling new MyAuthenticator(), it does not get inside the MyAuthenticator class.
    Why does this happen? What is the solution for this?

  • How to register a DataSource in JNDI

    I'm having a great deal of difficulty getting JNDI to work properly.
    I'm attempting to use Quartz scheduler in a test program using a Derby database to store the scheduled events. In order to do this, I must pass Quartz the JNDI name of the data source for the database connection.
    Unfortunately, virtually all of the documentation I've been able to find gives half of the story, and then says something to the like of "system properties required to actually make this work not shown". GRR!
    I did come across some code for setting up a service provider, but I get even more errors when I try to set up a data source:
         Hashtable<Object, Object> env = new Hashtable<Object, Object>();
         // env.put(Context.INITIAL_CONTEXT_FACTORY, "com.smardec.jndi.mirror.MirrorInitialCtxFactory");
         env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.FSContextFactory");
         env.put(Context.PROVIDER_URL, "file:/");
         Context context = new javax.naming.InitialContext(env);
         org.apache.derby.jdbc.ClientDataSource40 dataSource = new org.apache.derby.jdbc.ClientDataSource40();
         dataSource.setServerName("my_derby_database_server");
         dataSource.setDatabaseName("my_derby_database_name");
         context.bind("jdbc/quartzdb", dataSource);If I try to use MirrorJNDI, I get the following error:
    javax.naming.InvalidNameException: Cannot handle all components
    at com.smardec.jndi.mirror.MirrorCtx.getParsedName(MirrorCtx.java:90)
    at com.smardec.jndi.mirror.MirrorCtx.bind(MirrorCtx.java:133)
    at com.smardec.jndi.mirror.MirrorCtx.bind(MirrorCtx.java:160)
    at javax.naming.InitialContext.bind(InitialContext.java:400)
    If I try using FSContextFactory, I get the following error:
    javax.naming.OperationNotSupportedException: can't bind arbitrary objects in an FSContext
    at com.sun.jndi.fscontext.FSContext.bind(FSContext.java:180)
    at com.sun.jndi.fscontext.FSContext.bind(FSContext.java:167)
    at javax.naming.InitialContext.bind(InitialContext.java:400)
    Is there some simple way to just create and register a DataSource so that Quartz can find and use it?

    Hi Karl
    unfortunally i think that you can not store the org.apache.derby.jdbc.ClientDataSource40 object in the file system
    the problem is related to the implementation of the JNDI for the File System
    reading the officila SUN documentation you can find that
    "Java objects can be stored in the file system under the following conditions:"
    The initial factory is RefFSContextFactory (not FSContextFactory)
    The object is of type java.naming.Reference or implements java.naming.Referenceable
    anyway i post the official link of the official SUN documentation:
    for the SUM JNDI home page
    http://java.sun.com/javase/technologies/core/jndi/index.jsp
    hire the SUN SPI
    http://java.sun.com/products/jndi/serviceproviders.html
    where you have downloaded the jar for the File System SPI (check the doc folder... there is an exmple how to put and get objects in the file system)
    Bye
    Alessandro

  • How to insert a null value to combobox which is bind with datasource

    Hi,
    i am working on c# winforms application. I have 2 comboboxes one is CustomerCbBox and another is OrderCbBox. CustomerCbBox is bind with data source.
    on CustomerCbBox SelectedIndexChanged event data is populated in OrderCbBox from data source. 
    i want to add a null or empty field in CustomerCbBox. all I want is that when the user don't Select Customer Name and OrderNo null or empty data enter in database. but when i click Insert Button it generate error "Object reference is not "object
    reference not set to an instance of an object".
    here is my code.
      private void MainForm_Load(object sender, EventArgs e)
    production pd = new production();
    CustomerCbBox.DataSource = pd.Customer();
    CustomerCbBox.DisplayMember = "Cust";
    CustomerCbBox.ValueMember = "CustId";
     private void CustomerCbBox_SelectedIndexChanged(object sender, EventArgs e)
                      try
                          string PartyName = CustomerCbBox.SelectedIndex.ToString();
                           PONum1.DataSource = pd.GetPOnumActive(PartyName1);
                              PONum1.DisplayMember = "PONum";
                              PONum1.ValueMember = "PONum";
                      catch (Exception ex)
                          MessageBox.Show(ex.Message);
         Please help me to solve this problem thanks.      

    Hello,
    We could check whether the user has selected any items before adding that to database.
    if (CustomerCbBox.SelectedIndex > -1)
    // do something
    }else{//add dbnull to database}
    And for adding null to databse, we could pass DBNull.Value instead.
    Regards,
    Carl
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Setting v$session.program with javax.sql.DataSource unsing JNDI

    I am trying to set v$session's program column while connecting to database.
    It works like charm when i use :
    java.util.Properties params = new java.util.Properties();
    params.put("v$session.program", "MyApp");
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection("jdbc:oracle:thin:user/[email protected]:1521:myDB",params);
    It just doesn't SET anything when i use, JNDI :
    java.util.Properties params = new java.util.Properties();
    params.put("v$session.program", "MyApp");
    Context ctx = new InitialContext(params);
    DataSource ds = (DataSource)ctx.lookup(datasourceName);
    conn = ds.getConnection(userName,password);
    Just couldn't figure out why its not setting in the 2nd Case. Any ideas ??

    Valid..
    But then, even if i set v$session.program in my JDev environment or even on app server's connection pool Its NOt getting set.
    Am i doing something worng.
    Btw, i am using jdbc thin 10.1.0.3 driver. I read somewhere that this was a bug and its fixed with jdbc thin driver 10.2.x versions.
    Has anyone tried on 10.2.x versions ?

  • Bind remote object to JNDI tree

    I want to create a JNDI tree in the same JVM with remote object, and then I have two problem:
    1> Should I bind remote object or its stub to the JNDI tree?
    2> How to look up the JNDI tree to get the binded stub from the client side? (Suppose server ip is 192.168.99.42)
    I hope a gentleman would give me a piece of code, so i would be much clearer. Thanks a lot!

    Hi,
    Refer http://java.sun.com/products/jndi/tutorial/objects/storing/remote.html
    -amol

  • How to bind an object to JNDI tree in iAS?

    Hi all,
    When I try to bind a string object to jndi tree, the following exception
    occurs:
    javax.naming.NamingException: Unable to get object instance from reference.
    Roo
    t exception is javax.naming.NamingException: Can't bind instance of class
    java.lang.String
    at com.netscape.server.jndi.RootContext.bindCtx(Unknown Source)
    at com.netscape.server.jndi.RootContext.rebind(Unknown Source)
    at com.netscape.server.jndi.RootContext.rebind(Unknown Source)
    at javax.naming.InitialContext.rebind(InitialContext.java:385)
    at jsp.APPS.bmx.test2._jspService(test2.java:76)
    at jsp.APPS.bmx.test2.service(test2.java:42)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
    at
    com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown
    Source)
    The code fragment is:
    Context ctx = new InitialContext();
    String str = "hell,every one!";
    ctx.rebind("abc", str);
    Can anyone give some help? Thanks in advance.
    Johnson

    To bind an object into the JNDI tree check the documentation here:
    http://e-docs.bea.com/wls/docs81/jndi/jndi.html#475702
    If this is to be used by all your applications that you deploy on the server check out the startup/shutdown class documentation here:
    http://edocs.bea.com/wls/docs81/ConsoleHelp/startup_shutdown.html
    Cheers
    IV

  • DataSource and JNDI

    Ight guys i am soo confused... I am creating a connection pool and i have used the little tool to create the pool and the datasource.. Now how do i call the datasource to be able to retrieve the connection.. Sorry for the question i just am not understanding everything that i have been reading

    Well, your question is how to connect to an established connection pool? Are you sure your pool is actually working? You didn't post any code on how you set that up.Also, without the setup portion, we don't know what reference name you gave your connection pool, so we don't know how to look it up. Please post the portion of your server.xml where you created the resource and the portion of your web.xml where you reference it, and we can take it from there.

  • Bind RMI object to JNDI

    InitialContext ctx = new InitialContext ();
    ctx.rebind ("wwlhp", remoteObject);Does the JNDI tree and remoteObject reside in the same JVM?
    Can i use JNDI without J2EE platform?
    Can some one give me a piece of code illustrating rebinding in server side and looking up in client side.

    import javax.naming.*;
    import java.util.*;
    public class Server{
    public static void main(String[]args){
    try{
    Hashtable env=new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.rmi.registry.RegistryContextFactory");
    env.put(Context.PROVIDER_URL,"rmi://servername");
    Context ctx=new InitialContext(env);
    //create an instance of remote object
    RemoteIF i=new RemoteImpl();
    ctx.rebind("common name",ri);
    }catch(Exception ex){}
    The client needs to create a context as well, as above, the lookup
    RemoteIF ri=(RemoteIF)ctx.lookup("common name");
    The Stub classes must be available to the client as well
    start rmiregistry
    start the server
    off you go with the client

  • DataSource and ConnectionPoolDataSource

    Could someone explain how to bind a DataSource with JNDI so that it is pooled? The only way I can get it to work is to bind an OracleConnectionPoolDataSource and then lookup a ConnectionPoolDataSource and get the PooledConnection from that. The documentation says that a client should be able to use the pooled DataSource the same way as a non-pooled one. But, in my scenario the client has to get a PooledConnection then get a Connection from that.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Brad Lane ([email protected]):
    Could someone explain how to bind a DataSource with JNDI so that it is pooled? The only way I can get it to work is to bind an OracleConnectionPoolDataSource and then lookup a ConnectionPoolDataSource and get the PooledConnection from that. The documentation says that a client should be able to use the pooled DataSource the same way as a non-pooled one. But, in my scenario the client has to get a PooledConnection then get a Connection from that.<HR></BLOCKQUOTE>
    Sun's documentation says that you should be able to create a DataSource and call setDataSourceName() with the ConnectionPoolDataSource name. This doesn't seem to be supported in Oracle's implementation. Is this true? If so, Oracle's driver DOES NOT fully support the JDBC 2.0 Optional Package as they state in the documentation.
    Hello JDBC Dev. Team? Anyone out there?
    null

  • Registering datasource in websphere

    Hello,
    I am trying to implement connection pooling in websphere. I am using version 3.5, alonside db2. I have set up in the datasource in websphere, I then try to use the following code to establish the datasource and retrieve a connection from the pool.
         try {
              Hashtable parms = new Hashtable();
              parms.put (Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
              Context ctx = new InitialContext(parms);
              ds = (DataSource)ctx.lookup("jdbc/GFSI");
              ctx.close();
              con = ds.getConnection("uname","pword");
         } catch (Exception e) {}
    The datasource seems to be set up, but when I try to connect to it, I get an error message saying ..."incorrect database name". I have seen some threads talking about setting up the JNDI name, but I dont where I should be doing this.Any ideas/suggestions gratefully recieved.
    Thanks

    The code seems to be fine. Problem should be somewhere else. Please check the name of the database that you created on the db2 server and check whether your datasource is pointing to the same database (check the url parameter).Also check whether you have bind the same datasource with jndi name "jdbc/GFSI" in your WAS datasource configuration.
    You have :
    1) actual database name which is referred by the datasource through the url parameter.
    2) datasource name which is the reference for the naming server for binding the datasource with jndi name.
    3) jndi name for the datasource which is referred by your code for doing a jndi lookup.
    Probably one of the above names is miss-spelled somewhere.
    Regards,
    Ashoke Bhowmick

  • JBOSS jndi Datasource: jdbc not bound

    Im adding an jndi Datasource to JBOSS 4.0.2.
    1. i copied jdbc driver to JBOSS_HOME/server/default/lib.
    2. i copied following ds.xml to JBOSS_HOME/server/default/deploy (its based ony the mysql-ds.xml from the samples)
    <?xml version="1.0" encoding="UTF-8"?>
    <datasources>
      <local-tx-datasource>
        <jndi-name>jndi-name</jndi-name>
        <connection-url>jdbc:mysql://localhost:3306/databasename</connection-url>
        <driver-class>org.gjt.mm.mysql.Driver</driver-class>
        <user-name>username</user-name>
        <password>password</password>
        <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
        <!-- sql to call when connection is created
        <new-connection-sql>some arbitrary sql</new-connection-sql>
          -->
        <!-- sql to call on an existing pooled connection when it is obtained from pool
        <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
          -->
        <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
        <metadata>
           <type-mapping>mySQL</type-mapping>
        </metadata>
      </local-tx-datasource>
    </datasources>I look this up using java:jndi-name. Works perfect.
    For compatibility with other containers, i want to move my jndi-datasource to java:comp/env/jdbc/jndi-name
    So i change my ds-description:
    <?xml version="1.0" encoding="UTF-8"?>
    <datasources>
      <local-tx-datasource>
        <jndi-name>comp/env/jdbc/jndi-name</jndi-name>
        <connection-url>jdbc:mysql://localhost:3306/databasename</connection-url>
        <driver-class>org.gjt.mm.mysql.Driver</driver-class>
        <user-name>username</user-name>
        <password>password</password>
        <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
        <!-- sql to call when connection is created
        <new-connection-sql>some arbitrary sql</new-connection-sql>
          -->
        <!-- sql to call on an existing pooled connection when it is obtained from pool
        <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
          -->
        <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
        <metadata>
           <type-mapping>mySQL</type-mapping>
        </metadata>
      </local-tx-datasource>
    </datasources>Looking this up with java:comp/env/jdbc/jndi-name leads to Could not find datasource: java:comp/env/jdbc/jndi-name
    javax.naming.NameNotFoundException: jdbc not bound
    Some lines above jboss prints:
    [WrapperDataSourceService] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:name=comp/env/jdbc/jndi-name,service=DataSourceBinding to JNDI name 'java:comp/env/jdbc/jndi-name
    Please can somebody explain what the problem is about binding a datasource somewhere else than directly to "java:"

    In web.xml making the following entry:
    <web-app>
    <description>MySQL Test App</description>
    <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/test</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    </web-app>
    Next, add a file jboss-web.xml under WEB-INF/ folder of the web-application. This file should contain entry as:
    <jboss-web>
    <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/test</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <jndi-name>java:/jdbc/test</jndi-name>
    <res-auth>Container</res-auth>
    </resource-ref>
    </jboss-web>
    Next, in JBOSS_HOME/server/default/deploy folder make a xx-ds.xml file or else, a similiar file can be found in that same folder with the name hsqldb-ds.xml. Make following entries in that xml file:
    <datasources>
    <local-tx-datasource>
    <jndi-name>/jdbc/test</jndi-name>
    <type-mapping>MySQL</type-mapping>
    <connection-url>jdbc:mysql://localhost:3306/shopping_cart</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password>root123</password>
    <min-pool-size>1</min-pool-size>
    <max-pool-size>5</max-pool-size>
    </local-tx-datasource>
    This should bind the jndi name.
    In our client application, we need to look up as:
    Context ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:/jdbc/test");
    Connection conn = ds.getConnection();
    This works perfectly.

Maybe you are looking for

  • Adobe Creative Cloud installation funktioniert nicht

    Hallo, Ich habe folgendes Problem: Immer wenn ich CC installieren will kommt mir eine Windows Meldung mit Programm funktioniert nicht mehr Als ich es vor 1 Woche deinstalliert habe kam mir eine fehler meldung "fehler beim deinstallieren" danach habe

  • Viewing FCP on NTSC MONITOR

    In my days with PC I used to watch my timeling in Premier Pro on my NTSC monitor. I had a Matrox card with an outbox and connected the svideo out on the box to my monitor. Now in the Mac Pro I have dual outputs on my ATI Raden card and all I get on m

  • Ipod touch generation 5. Disabled, no luck restoring and is no longer recognised.

    Kids disabled it, I have tried restoring but it made me download an update first by which point it decided my Ipod was no longer recognised by my computer and still won't recognise it. I tried turning it off, then connected the usb, held down the pow

  • In lion seems a picture of a lion is on all my mail

    since getting my new imac with Lion.... seems that many of the emails i send out have a Lion pictured in the top right hand corner.... its a bit of a bother  Help

  • Automator ID3 tags

    Hi, I'm trying to organise my beatport files according to release date in Itunes. The filenames hold numbers, for example: 379980Electrostatic_OriginalRemastered.mp3 The problem is that Itunes doesn't provide a way to order the files according to fil