• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in Jndi LooK up in Was6.1 for MySql Data Source

 
Saket Kumar Sinha
Ranch Hand
Posts: 32
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please help me. I am stuck here for last two days.

i have Mysql 5.1 server installed and i have tested the connection from Websphere Admin console after setting the JDBC provider , Data Source and Java Authentication Alias. It shows me Test Connection Succeeded.

I have created a simple Web Project in NetBeans 6.1.
in web.xml i have used the resource ref

<resource-ref id="MySqlResourceRef">
<description>
</description>
<res-ref-name>jdbc/OMSDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

In Ibm binding.xml i ahve the following

<resRefBindings jndiName="jndi/MyOMSDB" xmi:id="ResourceReferenceBinding_MySqlResourceRef">
<bindingResourceRef href="WEB-INF/web.xml#MySqlResourceRef"/>
</resRefBindings>

I deployed the project and it works fine an started successfully.

Now i have written a sample java code to do the Look up

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL,"iiop://localhost:2809/");
javax.sql.DataSource ds = null;
Connection con =null;
System.out.println("Attempting connection..." );
try {
InitialContext ctx = new InitialContext(env);
ds = (javax.sql.DataSource) ctx.lookup("java:comp/env/jdbc/OMSDB");
System.out.println("Attempting connection..." );
con = ds.getConnection();
} catch (Exception e) {
System.out.println("peformanceappraisalstatus: COULDN'T CREATE CONNECTION!");
e.printStackTrace();
}


I have the IBM JRE which is present in Appserver / java folder and i have added sibc.jms.jar and sibc.jndi.jar in the lib folder.

I am getting the below exception. Please tell me how to do the look up. I have tried many things but everytime i got some error.

javax.naming.ConfigurationException: NamingManager.getURLContext cannot find the factory for this scheme: java
at com.ibm.ws.naming.jndicos.CNContextImpl.checkForUrlContext(CNContextImpl.java:3130)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1410)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookup(CNContextImpl.java:1293)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:145)
at javax.naming.InitialContext.lookup(InitialContext.java:436)

 
Saket Kumar Sinha
Ranch Hand
Posts: 32
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone please help me in solving this? What type of Jars i am missing.
I did the same thing when i created one simple Queue and QueueConnection factory and did the jndi look up through a java class and was able to send the message properly. i dont know why i am not able to do the same with the DataSource thing.
 
Saket Kumar Sinha
Ranch Hand
Posts: 32
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,

Now i am try to do it throgh stand alone client. here there is no web.xml and ibm binding .xmi

i have simply written a java class that does the jndi look up.

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL,"iiop://localhost:2809");
// env.put("org.omg.CORBA.ORBClass", "com.ibm.CORBA.iiop.ORB");

javax.naming.InitialContext ctx = null;
javax.sql.DataSource ds = null;
Object obj =null;
System.out.println("Attempting connection..." );
try {
ctx = new javax.naming.InitialContext(env);
System.out.println(ctx.getNameInNamespace());
obj= ctx.lookup("jndi/OMSDB");
ds = (javax.sql.DataSource)obj;
// ds = (javax.sql.DataSource) ctx.lookup("jndi/MyOMSDB");
System.out.println("Attempting connection..." );
// Connection connection = ds.getConnection();
} catch (Exception e) {
System.out.println("peformanceappraisalstatus: COULDN'T CREATE CONNECTION!");
e.printStackTrace();
}
System.out.println(obj);

I am getting the below exception marked in bold. i have the IBM jre and com.ibm.ws.admin.client_6.1.0.jar in lib. Please help....

Attempting connection...
SAKETNode01Cell/nodes/SAKETNode01/servers/server1
Apr 3, 2012 7:16:20 AM null null
WARNING: jndiGetObjInstNoop
peformanceappraisalstatus: COULDN'T CREATE CONNECTION!
java.lang.ClassCastException: javax.naming.Reference incompatible with javax.sql.DataSource
at omsdemo1.Main.main(Main.java:35)

Reference Class Name: javax.resource.cci.ConnectionFactory
Type: connectorName
Content: Oracle JDBC Driver DataSource
Type: classpath
Content: G:/Program Files/IBM/WebSphere/AppServer/lib/rsadapter.rar;G:/Program Files/IBM/WebSphere/AppServer/lib/rsadapter.rar
Type: FactoryJndiName
Content: jndi/OMSDB
The type of the address is: dd
The content of the address is: ffffffac ffffffed 0 5 73 72 0 25 63 6f 6d 2e 69 62 6d 2e 65 6a 73 2e 6a 32 63 2e 52 65 73 6f 75 72 63 65 41 64 61 70 74 65 72 44 44 49 6d 70 6c ffffffc3 ffffffac 4 ffffffb6 2c 65 30 ffffffd6 3 0 4 5a 0 17 72 65 61 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 53 75 70 70 6f 72 74 49 0 12 74 72 61 6e 73 61 63 74 69 6f 6e 53 75 70 70 6f 72 74 4c 0 b 63 66 49 6e 74 65 72 66 61 63 65 74 0 12 4c 6a 61 76 61 2f 6c 61
The type of the address is: miscProps
The content of the address is: ffffffac ffffffed 0 5 73 72 0 14 6a 61 76 61 2e 75 74 69 6c 2e 50 72 6f 70 65 72 74 69 65 73 39 12 ffffffd0 7a 70 36 3e ffffff98 2 0 1 4c 0 8 64 65 66 61 75 6c 74 73 74 0 16 4c 6a 61 76 61 2f 75 74 69 6c 2f 50 72 6f 70 65 72 74 69 65 73 3b 78 72 0 13 6a 61 76 61 2e 75 74 69 6c 2e 48 61 73 68 74 61 62 6c 65 13 ffffffbb f 25 21 4a ffffffe4 ffffffb8 3 0 2 46 0 a 6c 6f 61 64 46 61 63 74 6f 72 49 0 9 74 68 72
The type of the address is: poolProps
The content of the address is: ffffffac ffffffed 0 5 73 72 0 27 63 6f 6d 2e 69 62 6d 2e 65 6a 73 2e 6a 32 63 2e 43 6f 6e 6e 65 63 74 6f 72 50 6f 6f 6c 50 72 6f 70 65 72 74 69 65 73 e 2a ffffffd3 ffffff84 70 ffffffcb ffffffa9 15 3 0 13 4a 0 b 61 67 65 64 54 69 6d 65 6f 75 74 4a 0 11 63 6f 6e 6e 65 63 74 69 6f 6e 54 69 6d 65 6f 75 74 49 0 e 64 69 61 67 6e 6f 73 74 69 63 4d 6f 64 65 49 0 1d 66 72 65 65 50 6f 6f 6c 44 69 73 74 72 69 62 75
The type of the address is: configProps
The content of the address is: ffffffac ffffffed 0 5 73 72 0 23 63 6f 6d 2e 69 62 6d 2e 65 6a 73 2e 6a 32 63 2e 43 6f 6e 6e 65 63 74 6f 72 50 72 6f 70 65 72 74 69 65 73 fffffffc ffffff8d 1d ffffffaa 26 ffffff85 ffffffc7 34 2 0 0 78 72 0 10 6a 61 76 61 2e 75 74 69 6c 2e 56 65 63 74 6f 72 ffffffd9 ffffff97 7d 5b ffffff80 3b ffffffaf 1 3 0 3 49 0 11 63 61 70 61 63 69 74 79 49 6e 63 72 65 6d 65 6e 74 49 0 c 65 6c 65 6d 65 6e 74 43 6f 75 6e 74 5b 0 b 65 6c 65 6d 65
The type of the address is: mmProps
The content of the address is: ffffffac ffffffed 0 5 73 72 0 14 6a 61 76 61 2e 75 74 69 6c 2e 50 72 6f 70 65 72 74 69 65 73 39 12 ffffffd0 7a 70 36 3e ffffff98 2 0 1 4c 0 8 64 65 66 61 75 6c 74 73 74 0 16 4c 6a 61 76 61 2f 75 74 69 6c 2f 50 72 6f 70 65 72 74 69 65 73 3b 78 72 0 13 6a 61 76 61 2e 75 74 69 6c 2e 48 61 73 68 74 61 62 6c 65 13 ffffffbb f 25 21 4a ffffffe4 ffffffb8 3 0 2 46 0 a 6c 6f 61 64 46 61 63 74 6f 72 49 0 9 74 68 72
The type of the address is: dsProps
The content of the address is: ffffffac ffffffed 0 5 73 72 0 14 6a 61 76 61 2e 75 74 69 6c 2e 50 72 6f 70 65 72 74 69 65 73 39 12 ffffffd0 7a 70 36 3e ffffff98 2 0 1 4c 0 8 64 65 66 61 75 6c 74 73 74 0 16 4c 6a 61 76 61 2f 75 74 69 6c 2f 50 72 6f 70 65 72 74 69 65 73 3b 78 72 0 13 6a 61 76 61 2e 75 74 69 6c 2e 48 61 73 68 74 61 62 6c 65 13 ffffffbb f 25 21 4a ffffffe4 ffffffb8 3 0 2 46 0 a 6c 6f 61 64 46 61 63 74 6f 72 49 0 9 74 68 72
The type of the address is: mcfProps
The content of the address is: ffffffac ffffffed 0 5 73 72 0 2d 63 6f 6d 2e 69 62 6d 2e 65 6a 73 2e 6a 32 63 2e 4d 61 6e 61 67 65 64 43 6f 6e 6e 65 63 74 69 6f 6e 46 61 63 74 6f 72 79 50 72 6f 70 73 ffffffd3 21 53 ffffffb4 ffffffca ffffffd2 65 24 3 0 1 4c 0 15 43 6f 6e 6e 65 63 74 69 6f 6e 46 61 63 74 6f 72 79 54 79 70 65 74 0 13 4c 6a 61 76 61 2f 6c 61 6e 67 2f 49 6e 74 65 67 65 72 3b 78 70 73 72 0 11 6a 61 76 61 2e 6c 61 6e 67 2e 49 6e
The type of the address is: mbeanProps
The content of the address is: ffffffac ffffffed 0 5 73 72 0 1a 63 6f 6d 2e 69 62 6d 2e 65 6a 73 2e 6a 32 63 2e 4d 42 65 61 6e 50 72 6f 7
 
Dirk Huth
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi -

I have the same problem on WASv7 and mySQL 5.1:

on the AdminConsole I get a "test connection successful"
but the sample application fails with "com.ibm.ws.naming.jndicos.CNContextImpl incompatible with javax.sql.DataSource"

No clue as to how to fix it. Have you come any further?

Best greetings,

Dirk
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic