File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "DataSouce accessing in JBoss4.o " Watch "DataSouce accessing in JBoss4.o " New topic
Author

DataSouce accessing in JBoss4.o

sudhakar udatha
Greenhorn

Joined: Nov 06, 2007
Posts: 4
Hi

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

<datasources>
<local-tx-datasource>
<jndi-name>MySqlDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/mytables</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>mysql</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>


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

<datasource>java:/MySqlDS</datasource>
<type-mapping>mySQL</type-mapping>
<debug>false</debug>
3) I set the <datasource> and <datasource-mapping> elements in the standardjbosscmp-jdbc.xml and then modify following way

<jbosscmp-jdbc>
<defaults>
<datasource>java:/MySqlDS</datasource>
<datasource-mapping>mySQL</datasource-mapping>
</defaults>
</jbosscmp-jdbc>

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">
<authentication>
<login-module code ="org.jboss.resource.security.ConfiguredIdentityLoginModule"
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">
jboss.jca:service=LocalTxCM,name=MySqlDS
</module-option>
</login-module>
</authentication>
</application-policy>

5) this is my client program accesing the datasource

FleInputStream fis=new FileInputStream("Jndi1.Properties");
Properties props= System.getProperties();
props.load(fis);
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);
conn.close();

5) this is my jndi properties file

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming rg.jnp.interfaces

6) this is my Exception
load the properties
context
context
javax.naming.NameNotFoundException: MySqlDS not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
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$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Sour
ce)
at java.lang.Thread.run(Unknown 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(NamingContext.java:610)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
at javax.naming.InitialContext.lookup(Unknown Source)
at JndiCls.main(JndiCls.java:21)


Please clarify my program
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9913
    
158

Sudhakar,

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: http://aspose.com/file-tools
 
subject: DataSouce accessing in JBoss4.o
 
Similar Threads
Problem in getting the datasource for mysql
Probles in setting datasource
JBoss 4.0 and MSSQL Server 2000
Error connecting to Oracle database during Jboss startup
how debug a CMP entity error?