Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

DataSouce accessing in JBoss4.o  RSS feed

sudhakar udatha
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 10447
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!