Topic
  • 10 replies
  • Latest Post - ‏2013-04-25T14:23:30Z by bpaskin
Dorairaj M
Dorairaj M
7 Posts

Pinned topic DataSource creation in Server configured in eclipse

‏2013-04-22T04:43:15Z |

Hi All,

I am new to Websphere, Can any one let me know how to create Datasource in server which configured in eclipse through liberty profile and how to open admin console.

I have noticed few issue when i run the server in eclipse but not in the server when i run through start program option. Please let me know differences both of these settings ?

Note: I am able to create the datasource in server opened through start program option

 

Thanks

Dorairaj M

  • bpaskin
    bpaskin
    4988 Posts
    ACCEPTED ANSWER

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-24T14:21:09Z  

    Hi Brian,

    By removing the hashtable from code it is working with the profile server, but not in the Liberty profile server , following exception is displaying

    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

    am i wrong in datasource creation in liberty profile? following is my datasource connection configuration in server.xml file :

    <library id="Oracle">
            <fileset id="Oracle" dir="D:\jar" includes="ojdbc14.jar"/>
        </library>
        
        <jdbcDriver libraryRef="Oracle" id="OJDBC-Driver"/>
        
        <dataSource jndiName="SSF_512_DEV"
            jdbcDriverRef="OJDBC-Driver"
            type="javax.sql.ConnectionPoolDataSource" id="SSF_512_DEV">
            <properties.oracle databaseName="UTF102" serverName="Logan" user="SSF_512_DEV"
                password="CLINAPPS" URL="jdbc:oracle:thin:@Logan:1521:UTF102"/>
        </dataSource>

     

    Code i used is :

     

            localCtx = new InitialContext( );
            
            localDataSource = (DataSource) localCtx.lookup("SSF_512_DEV");
            localConnection = localDataSource.getConnection();

     

    Thanks

    Dorairaj M

    Hi, Did you add anything to your web.xml?  try changing the lookup to "java:comp/env/SSF_512_DEV".  Also you need to use the ojdbc6.jar file.  ojdbc14 is for Java 1.4 not for Java 5 or Java 6.

    Regards,

    Brian

  • bpaskin
    bpaskin
    4988 Posts
    ACCEPTED ANSWER

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-25T14:23:30Z  

    Hi Brian,

    Ok.

    Can you please let me know about the below issue, this is observing only on Datasource connection

    [ERROR   ] J2CA0081E: Method cleanup failed while trying to execute method cleanup on ManagedConnection WSRdbManagedConnectionImpl@12934a1 from resource SSF_512_DEV/connectionManager-default. Caught exception: com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException: DSRA0080E: An exception was received by the Data Store Adapter. See original exception message: Cannot call 'cleanup' on a ManagedConnection while it is still in a transaction..

    Hi, you need to commit or rollback your transaction and DB query.  It cannot do anything with the connection until the connection is properly terminated.

    Regards,

    Brian

  • Dorairaj M
    Dorairaj M
    7 Posts

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-23T05:11:53Z  

    Anybody can reply to this?

     

    Dorairaj

  • bpaskin
    bpaskin
    4988 Posts

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-23T12:33:19Z  

    Anybody can reply to this?

     

    Dorairaj

    Hi, You have to give a little more time before someone replies.

    Please see this example for the Liberty Profile: http://www.ibm.com/developerworks/websphere/techjournal/1212_ramachandra/1212_ramachandra.html under the section "Defining the data source"

    Regards, Brian

  • Dorairaj M
    Dorairaj M
    7 Posts

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-24T09:24:01Z  
    • bpaskin
    • ‏2013-04-23T12:33:19Z

    Hi, You have to give a little more time before someone replies.

    Please see this example for the Liberty Profile: http://www.ibm.com/developerworks/websphere/techjournal/1212_ramachandra/1212_ramachandra.html under the section "Defining the data source"

    Regards, Brian

    Hi bpaskin,

    Thanks for your reply !!..

    Ok.

    I have gone through the link and created Datasource, however unable to get the connection due to the following exception

    javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory

    java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory

    below is my code

    Hashtable localHt = new Hashtable();

            localHt.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
            localHt.put(Context.PROVIDER_URL, "corbaname:iiop://localhost:9081");
            
            localCtx = new InitialContext(
                localHt);
            
            localDataSource = (DataSource) localCtx.lookup(dataSourceArg);
            localConnection = localDataSource.getConnection();

     

    Here is my datasource configuration from server.xml file

     

     <dataSource commitOrRollbackOnCleanup="rollback"
        connectionSharing="MatchOriginalRequest" id="SSF_512_DEV" jndiName="SSF_512_DEV"
        type="javax.sql.ConnectionPoolDataSource" jdbcDriverRef="Oracle-UTF">
        <jdbcDriver libraryRef="OracleID" id="OracleID">
        </jdbcDriver>
        <properties.oracle databaseName="UTF102" serverName="Logan"
            user="SSF_512_DEV" URL="jdbc:oracle:thin:@logan:1521:UTF102" />
        </dataSource>

     

     

    Thanks

    Dorairaj M

     

  • bpaskin
    bpaskin
    4988 Posts

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-24T11:36:09Z  

    Hi bpaskin,

    Thanks for your reply !!..

    Ok.

    I have gone through the link and created Datasource, however unable to get the connection due to the following exception

    javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory

    java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory

    below is my code

    Hashtable localHt = new Hashtable();

            localHt.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
            localHt.put(Context.PROVIDER_URL, "corbaname:iiop://localhost:9081");
            
            localCtx = new InitialContext(
                localHt);
            
            localDataSource = (DataSource) localCtx.lookup(dataSourceArg);
            localConnection = localDataSource.getConnection();

     

    Here is my datasource configuration from server.xml file

     

     <dataSource commitOrRollbackOnCleanup="rollback"
        connectionSharing="MatchOriginalRequest" id="SSF_512_DEV" jndiName="SSF_512_DEV"
        type="javax.sql.ConnectionPoolDataSource" jdbcDriverRef="Oracle-UTF">
        <jdbcDriver libraryRef="OracleID" id="OracleID">
        </jdbcDriver>
        <properties.oracle databaseName="UTF102" serverName="Logan"
            user="SSF_512_DEV" URL="jdbc:oracle:thin:@logan:1521:UTF102" />
        </dataSource>

     

     

    Thanks

    Dorairaj M

     

    Hi, the Hashtable is not needed if you are running in the same container.  To access the DataSource then you need to code the following:

    Context ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("OracleID");
    

    It is best practices to prefix your Datasources with jdbc in the configuration then access it via jdbc/OracleID.

    Regards,

    Brian

  • Dorairaj M
    Dorairaj M
    7 Posts

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-24T13:36:55Z  
    • bpaskin
    • ‏2013-04-24T11:36:09Z

    Hi, the Hashtable is not needed if you are running in the same container.  To access the DataSource then you need to code the following:

    <pre dir="ltr">Context ctx = new InitialContext(); DataSource ds = (DataSource)ctx.lookup("OracleID"); </pre>

    It is best practices to prefix your Datasources with jdbc in the configuration then access it via jdbc/OracleID.

    Regards,

    Brian

    Hi Brian,

    By removing the hashtable from code it is working with the profile server, but not in the Liberty profile server , following exception is displaying

    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

    am i wrong in datasource creation in liberty profile? following is my datasource connection configuration in server.xml file :

    <library id="Oracle">
            <fileset id="Oracle" dir="D:\jar" includes="ojdbc14.jar"/>
        </library>
        
        <jdbcDriver libraryRef="Oracle" id="OJDBC-Driver"/>
        
        <dataSource jndiName="SSF_512_DEV"
            jdbcDriverRef="OJDBC-Driver"
            type="javax.sql.ConnectionPoolDataSource" id="SSF_512_DEV">
            <properties.oracle databaseName="UTF102" serverName="Logan" user="SSF_512_DEV"
                password="CLINAPPS" URL="jdbc:oracle:thin:@Logan:1521:UTF102"/>
        </dataSource>

     

    Code i used is :

     

            localCtx = new InitialContext( );
            
            localDataSource = (DataSource) localCtx.lookup("SSF_512_DEV");
            localConnection = localDataSource.getConnection();

     

    Thanks

    Dorairaj M

    Updated on 2013-04-24T13:38:14Z at 2013-04-24T13:38:14Z by Dorairaj M
  • bpaskin
    bpaskin
    4988 Posts

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-24T14:21:09Z  

    Hi Brian,

    By removing the hashtable from code it is working with the profile server, but not in the Liberty profile server , following exception is displaying

    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

    am i wrong in datasource creation in liberty profile? following is my datasource connection configuration in server.xml file :

    <library id="Oracle">
            <fileset id="Oracle" dir="D:\jar" includes="ojdbc14.jar"/>
        </library>
        
        <jdbcDriver libraryRef="Oracle" id="OJDBC-Driver"/>
        
        <dataSource jndiName="SSF_512_DEV"
            jdbcDriverRef="OJDBC-Driver"
            type="javax.sql.ConnectionPoolDataSource" id="SSF_512_DEV">
            <properties.oracle databaseName="UTF102" serverName="Logan" user="SSF_512_DEV"
                password="CLINAPPS" URL="jdbc:oracle:thin:@Logan:1521:UTF102"/>
        </dataSource>

     

    Code i used is :

     

            localCtx = new InitialContext( );
            
            localDataSource = (DataSource) localCtx.lookup("SSF_512_DEV");
            localConnection = localDataSource.getConnection();

     

    Thanks

    Dorairaj M

    Hi, Did you add anything to your web.xml?  try changing the lookup to "java:comp/env/SSF_512_DEV".  Also you need to use the ojdbc6.jar file.  ojdbc14 is for Java 1.4 not for Java 5 or Java 6.

    Regards,

    Brian

  • Dorairaj M
    Dorairaj M
    7 Posts

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-25T04:42:47Z  
    • bpaskin
    • ‏2013-04-24T14:21:09Z

    Hi, Did you add anything to your web.xml?  try changing the lookup to "java:comp/env/SSF_512_DEV".  Also you need to use the ojdbc6.jar file.  ojdbc14 is for Java 1.4 not for Java 5 or Java 6.

    Regards,

    Brian

     

    Thanks your great support and your patients on this thread Brian,

    Adding the followng code to web.xml is solved the problem without appending the java:com/env, however it is working in Prifile server without having configuration in web.xml, i agree with you it is best practice to append jadbc infront of datasource

    <resource-ref>
            <description>Oracle Datasource </description>
            <res-ref-name>SSF_512_DEV</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
     </resource-ref>

    Inspite of these i have few clarifications i am getting below exception when I am using datasource, can please let me know why it displaying and how to fix 

    [ERROR   ] J2CA0081E: Method cleanup failed while trying to execute method cleanup on ManagedConnection WSRdbManagedConnectionImpl@12934a1 from resource SSF_512_DEV/connectionManager-default. Caught exception: com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException: DSRA0080E: An exception was received by the Data Store Adapter. See original exception message: Cannot call 'cleanup' on a ManagedConnection while it is still in a transaction..

    Why i am getting java.lang.ClassNotFoundException: when i use this class com.ibm.websphere.naming.WsnInitialContextFactory, i am Curious know about that because right now we are using weblogic server and one of our client is asking for websphere, earlier we have used the hastable in code, it is not good to remove that without having proper reason for webpshere. the code should be work for both weblogic and websphere.

    Hope you understand !!..

     

    Thanks

    Dorairaj

     

     

  • bpaskin
    bpaskin
    4988 Posts

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-25T11:48:45Z  

     

    Thanks your great support and your patients on this thread Brian,

    Adding the followng code to web.xml is solved the problem without appending the java:com/env, however it is working in Prifile server without having configuration in web.xml, i agree with you it is best practice to append jadbc infront of datasource

    <resource-ref>
            <description>Oracle Datasource </description>
            <res-ref-name>SSF_512_DEV</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
     </resource-ref>

    Inspite of these i have few clarifications i am getting below exception when I am using datasource, can please let me know why it displaying and how to fix 

    [ERROR   ] J2CA0081E: Method cleanup failed while trying to execute method cleanup on ManagedConnection WSRdbManagedConnectionImpl@12934a1 from resource SSF_512_DEV/connectionManager-default. Caught exception: com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException: DSRA0080E: An exception was received by the Data Store Adapter. See original exception message: Cannot call 'cleanup' on a ManagedConnection while it is still in a transaction..

    Why i am getting java.lang.ClassNotFoundException: when i use this class com.ibm.websphere.naming.WsnInitialContextFactory, i am Curious know about that because right now we are using weblogic server and one of our client is asking for websphere, earlier we have used the hastable in code, it is not good to remove that without having proper reason for webpshere. the code should be work for both weblogic and websphere.

    Hope you understand !!..

     

    Thanks

    Dorairaj

     

     

    Hi, Did you commit or rollback your query and transaction? 

    com.ibm.websphere.naming.WsnInitialContextFactory is not part of the Liberty Profile.  Furthermore, even in full WAS it is not needed when internal within container, only when outside the container, like a program accessing the code from the command line.  This would also be the case for WL, as it is part of the Java Spec.

    Even if you are going from a full version of WL and you want the exact same functions, then test in WAS and not in Liberty, which is just a subset of WAS.

    Regards, Brian

  • Dorairaj M
    Dorairaj M
    7 Posts

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-25T13:19:12Z  
    • bpaskin
    • ‏2013-04-25T11:48:45Z

    Hi, Did you commit or rollback your query and transaction? 

    com.ibm.websphere.naming.WsnInitialContextFactory is not part of the Liberty Profile.  Furthermore, even in full WAS it is not needed when internal within container, only when outside the container, like a program accessing the code from the command line.  This would also be the case for WL, as it is part of the Java Spec.

    Even if you are going from a full version of WL and you want the exact same functions, then test in WAS and not in Liberty, which is just a subset of WAS.

    Regards, Brian

    Hi Brian,

    Ok.

    Can you please let me know about the below issue, this is observing only on Datasource connection

    [ERROR   ] J2CA0081E: Method cleanup failed while trying to execute method cleanup on ManagedConnection WSRdbManagedConnectionImpl@12934a1 from resource SSF_512_DEV/connectionManager-default. Caught exception: com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException: DSRA0080E: An exception was received by the Data Store Adapter. See original exception message: Cannot call 'cleanup' on a ManagedConnection while it is still in a transaction..

  • bpaskin
    bpaskin
    4988 Posts

    Re: DataSource creation in Server configured in eclipse

    ‏2013-04-25T14:23:30Z  

    Hi Brian,

    Ok.

    Can you please let me know about the below issue, this is observing only on Datasource connection

    [ERROR   ] J2CA0081E: Method cleanup failed while trying to execute method cleanup on ManagedConnection WSRdbManagedConnectionImpl@12934a1 from resource SSF_512_DEV/connectionManager-default. Caught exception: com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException: DSRA0080E: An exception was received by the Data Store Adapter. See original exception message: Cannot call 'cleanup' on a ManagedConnection while it is still in a transaction..

    Hi, you need to commit or rollback your transaction and DB query.  It cannot do anything with the connection until the connection is properly terminated.

    Regards,

    Brian