• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

EJB connect with Mysql

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I want to use an entity Bean (Bean-Managed Persistence) to connect with the mysql DB, how should I configure the Datasource or the JDBC driver?
Like:
try{
.....
ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(
"java:comp/env/jdbc/<dbname>");
con = ds.getConnection();
....}

where should I give them teh correct JDBC driver:
---org.git.mm.mysql.Driver
and the datasource:
---("jdbc:mysql://host ort/<dbname>?use=..?password=...")

Thanks,
Roy
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should set DataSource somewhere in your app server by editing xml files or clicking some GUI.
Then you just see JNDI name:
Here is the sample for WebSphere but it works for Jboss !
Connection con = null;
String dsName = EnviromentUtil.getEnvString("nameDS");
try {
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(dsName);
con = ds.getConnection();
} catch (NamingException nex) {
throw new SQLException("Custom: Unable to get connection from DS");
}

Enviroment for that entity has
<env-entry>
<env-entry-name>nameDS</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>jdbc/Arhiv</env-entry-value>
</env-entry>

where jdbc/Arhiv is JNDI datasource name (app server dependant configuration)
 
Roy Huang
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Vladimir,
I think it is clear to me about it.
Have a nice weekend,
Roy
 
Your buns are mine! But you can have this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic