• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Accessing DataSource outside container

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello,

I wrote a standalone java application and this application needs to access the DB through the Data Sources that were established in Web Sphere. This application will not be deployed in Web Sphere but i will have to get the connection properties or connections from Web Sphere Data Sources itself.

All, I need was the connection properties..so that I can use them and connect from my standalone application. If I can access the data sources and get the connection that is well and good and if that is not possible is there any way that I can get the connection properties from the server and use in my java application to connect to the data base ?

Please, help.

Thanks.
 
Rahul Chaitanya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So far.. I was able to write the following code: "Idea is to build the websphere context through java code and then access its datasource".

Properties prop = new Properties();

prop.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");

prop.put(Context.PROVIDER_URL,"iiop://localhost:2811");

InitialContext init = new InitialContext(prop);

DataSource ds = (DataSource) init.lookup("jdbc/testDS");

But the problem is.. I was not able to identify the IIOP port number to use in the above code ? Does anybody has any idea about finding the iiop port number ?

 
Rahul Chaitanya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well..I was able to identify the port number in the following manner:

FROM WAS ADMIN CONSOLE: SERVERS -> APPLICATION SERVERS -> Under Communications -> Expand Ports

Now, I am getting an other error when I am trying to get the connection:

Properties prop = new Properties();

prop.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
prop.put(Context.PROVIDER_URL,"iiop://localhost:2811");

InitialContext init = new InitialContext(prop);

DataSource ds = (DataSource) init.lookup("jdbc/testDS");

//Connection conn = ds.getConnection("USER NAME","PASSWORD");
Connection conn = ds.getConnection();

If, I give the username/pwd while retrieving the connection it is working but it is not working if i don't give them. Since, I am thinking that it is not possible to get data source of websphere externally without authentication. But I guess setting up the authentication alias will be able to solve the problem. I tried it to but no luck.

Please, let me know if anybody has any information in retrieving the data source through custom properties/authentication alias ??

Thanks.

 
Sheriff
Posts: 28395
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't really expect to use that data source without providing the authentication details, do you? And when you do provide those details, you can access the data source successfully. I would say you have a solution already.
 
Rahul Chaitanya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for your reply Paul.

But the idea is to have the DB information in one place and have all the application to use it.

So..I will have to grab the connection properties from websphere data source without providing the user credentials and so I build the websphere context and did a look up for the JNDI. But was not able to get the connection without providing the user credentials.

Is there any other way where I can get the user credentials from the data source itself ?

I heard that establishing authentication properties through custom properties might solve the problem but I tried establishing them with names: user and password. But even that approach failed.

Any suggestions will be greatly appreciated.

Thanks,
Kireet Pola.
 
Paul Clapham
Sheriff
Posts: 28395
100
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It appears you have completely missed the point of securing the data source. If it were possible for any application to use the data source without providing any security credentials, there would be no point in having those security credentials. So a solution in which your application connects to the data source and presents the credentials is perfectly normal. Solutions in which you somehow get hold of the data source without doing that do not exist.
 
Rahul Chaitanya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, authentication alias doesn't seems to be getting applied and so it is expecting me to provide those details specifically. I completely agree with you but my requirement is to grab the connection from the websphere itself since, the idea is to maintain the db information in 1 place.

Please, let me know if there is any other way for retrieving the DB credentials from the data source itself.

Thanks.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which version of WebSphere Application Server do you use?
which version of Data source do you use?
 
Rahul Chaitanya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, we are using WAS 6.1 and I am not sure about the version of DS. But if there is a solution then I will be really happy to know about it although we decided to not to go over this approach of accessing data ource for getting the connections to a standalone application.

Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic