aspose file tools*
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
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "App Server DataSource" Watch "App Server DataSource" New topic
Author

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.

<datasources>
<local-tx-datasource>
<jndi-name>MySqlDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/database_name</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>jboss</user-name>
<password>password</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>

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
<resource-ref>
<res-ref-name>EntityDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
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.
 
 
subject: App Server DataSource