File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JBoss/WildFly and the fly likes DataSouce accessing in JBoss4.o Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "DataSouce accessing in JBoss4.o " Watch "DataSouce accessing in JBoss4.o " New topic

DataSouce accessing in JBoss4.o

sudhakar udatha

Joined: Nov 06, 2007
Posts: 4

i hava used jboss-4.0.2 and java5 with MySQL

1) First i put the MySQL driver classes into the CLASSPATH. Copy the .jar file mysql-connector-java-3.0.9-stable-bin.jar to the /server/default/lib directory. and then modify following way

<!-- 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) -->

2)Next,i set the <datasource> and <type-mapping> elements in the standardjaws.xml file: and then modify following way

3) I set the <datasource> and <datasource-mapping> elements in the standardjbosscmp-jdbc.xml and then modify following way


4) Finally, i modify login-config.xml with MySQL database settings. Add the following <application-policy/> element to login-config.xml:

<application-policy name = "MySqlDbRealm">
<login-module code =""
flag = "required">
<module-option name ="principal">sa</module-option>
<module-option name ="userName">sa</module-option>
<module-option name ="password"></module-option>
<module-option name ="managedConnectionFactoryName">

5) this is my client program accesing the datasource

FleInputStream fis=new FileInputStream("Jndi1.Properties");
Properties props= System.getProperties();
System.out.println("load the properties");
Context ic = new InitialContext(props);
System.out.println ("context");
DataSource ds=(DataSource)ic.lookup("java:/MySqlDS");
Connection conn=ds.getConnection();
System.out.println ("connection is"+conn);

5) this is my jndi properties file

java.naming.factory.url.pkgs=org.jboss.naming rg.jnp.interfaces

6) this is my Exception
load the properties
javax.naming.NameNotFoundException: MySqlDS not bound
at org.jnp.server.NamingServer.getBinding(
at org.jnp.server.NamingServer.getBinding(
at org.jnp.server.NamingServer.getObject(
at org.jnp.server.NamingServer.lookup(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$ Source)
at Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ Sour
at Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknow
n Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(
at org.jnp.interfaces.NamingContext.lookup(
at javax.naming.InitialContext.lookup(Unknown Source)
at JndiCls.main(

Please clarify my program
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441


Welcome to JavaRanch

Going by the exception stacktrace, it looks like you are looking up the datasource from a standalone java client. By default, the datasources are bound to the java: namespace in JNDI and hence are not available outside the JVM of the server. Have a look at HowCanIAccessADataSourceFromAClient if you want to bind the datasource in the global JNDI namespace.

[My Blog] [JavaRanch Journal]
I agree. Here's the link:
subject: DataSouce accessing in JBoss4.o
It's not a secret anymore!