• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

App Server DataSource

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic