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 EJB connect with Mysql 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 "EJB connect with Mysql" Watch "EJB connect with Mysql" New topic

EJB connect with Mysql

Roy Huang
Ranch Hand

Joined: Nov 21, 2001
Posts: 104
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?
ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(
con = ds.getConnection();

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


SCJP 1.4/SCBCD/SCWCD<br />MCSE<br />IBM professional XML Developer<br />SAP certified Development Consultant (NetWeaver portal and Web JavaApplication)
Vladimir Ergovic
Ranch Hand

Joined: Apr 22, 2001
Posts: 63
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

where jdbc/Arhiv is JNDI datasource name (app server dependant configuration)

Vladimir Ergovic
Roy Huang
Ranch Hand

Joined: Nov 21, 2001
Posts: 104
Thanks, Vladimir,
I think it is clear to me about it.
Have a nice weekend,
I agree. Here's the link:
subject: EJB connect with Mysql
It's not a secret anymore!