File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Connect DS with JNDI in JBoss AS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Connect DS with JNDI in JBoss AS" Watch "Connect DS with JNDI in JBoss AS" New topic

Connect DS with JNDI in JBoss AS

Hari Dhanakoti
Ranch Hand

Joined: Jan 07, 2008
Posts: 74
I had been trying to connect databases with JBoss4.2.2 thru JNDI. I had created a new xml file to locate the datasource to connect in the deploy directory. I have a problem of how to locate the JNDI file and how to establish the connection.

Here is my code of MSSQL-DS.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- =========================================================== -->
<!-- -->
<!-- DataDirect Data Sources -->
<!-- -->
<!-- =========================================================== -->
See the generic_ds.xml file in the doc/examples/jca folder
for examples of properties and other tags you can specify
in data sources
<!-- JBossTest Data Source -->
<!-- Driver Specific Options -->
<connection-property name="sendStringParametersAsUnicode">false</connection-property>
<!--pooling parameters-->

Here i try to connect thru JNDI in java code as

public void getConnection(){
InitialContext cxt = InitialContext.lookup("java:/MSSQLDS");
I am sure with the first step of the connection establishment but how to establish connection from this piece of code.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

Welcome to JavaRanch!

First you create an empty initial context. JBoss maps this to the JNDI. Then you lookup the datasource. The JNDI name comes from the XML, not the filename. I see a personDS in your example, but not a MSSQLDS one. Then you can get the connection from the datasource.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Connect DS with JNDI in JBoss AS
It's not a secret anymore!