File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes App Server DataSource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "App Server DataSource" Watch "App Server DataSource" New topic

App Server DataSource

Balamaci Serban
Ranch Hand

Joined: Mar 16, 2005
Posts: 49
The ideea is that components need to be App Server independent. Could it be said "use the default datasource of the App Server". The method that i used till now(I'm using JBoss AS) to connect to the database is that i have this mysql-ds.xml which binds MySqlDS to JNDI.


So whenever i want to talk to the database i say
Context ctx=new InitialContext();
DataSource ds=(javax.sql.DataSource) ctx.lookup("MySqlDS");

But what would happen if i needed to deploy the bean on an appserver that does not have a MySqlDS(i gave it that name) entry in the JNDI.

I don't understand what good does it do to write the ejb-jar.xml
maybe here it lies the answer to the use the default conection problem

Context ctx=new InitialContext();
DataSource ds=(javax.sql.DataSource) ctx.lookup("EntityDS");

Does the <res-type>javax.sql.DataSource</res-type> mean use the default connection of the server to a database?

But how do you specify which datase(catalog) to use? Only place where I've seen it is in the <connection-url>jdbc:mysql://localhost:3306/database_name</connection-url> in the mysql-ds.xml

Problem is that i think there has to be another way. I mean u would not edit mysql-ds.xml and put a new <datasources> entry with the name that a new bean uses and point to the database(catalog) that my bean's tables are inside of, and stop the server and get it back online. You don;t bring down the appserver whenever a bean needs to be deployed.
I agree. Here's the link:
subject: App Server DataSource
It's not a secret anymore!