File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Data Source Connection with MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Data Source Connection with MySQL" Watch "Data Source Connection with MySQL" New topic

Data Source Connection with MySQL

Jeanne Harris

Joined: May 07, 2012
Posts: 3
I have been working my way through the book "Beginning Java EE 5" using eclipse and jboss with mysql. In Chap 7 they have an example that is using a DataSource and connection in a JSP. I want to have it connect to MySQL database. I created a database called DataSourceExample and added a table to it and two records.

I wanted to attaching the original DataSourceExample.jsp files but they are not allowed.

My question is what do I change to connect to the MySQL database?

Part of the code from DataSourceExample.jsp

<% InitialContext context = new InitialContext();
DataSource dataSource =
(DataSource) context.lookup("java:comp/env/jdbc/DataSourceExample");
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
conn = dataSource.getConnection();

Here is the original web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns=""
version="2.5" >
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

you need a ???-ds.xml (datasource xml file) which contains the physical server address port, userid password etc.

something like (This is DB2): (Provide your own values for $VALUES$)

Jeanne Harris

Joined: May 07, 2012
Posts: 3
I am running with JBOSS 7.0

I created the file called my-ds.xml and put it into the WebContent\WEB-INF directory.

<password>my password</password>

When I run I get this error message.

Here is the whole jsp file.

07:08:23,802 INFO [] (DeploymentScanner-threads - 2) Found 07-exp1.war in deployment directory. To trigger deployment create a file called 07-exp1.war.dodeploy
07:08:23,824 INFO [] (MSC service thread 1-4) Starting deployment of "07-exp1.war"
07:08:24,058 INFO [] (DeploymentScanner-threads - 1) Deployment of "07-exp1.war" was rolled back with failure message {"Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"07-exp1.war\".jndiDependencyService missing [ ]","\"07-exp1.war\".module.07-exp1.07-exp1.0 missing [ ]"]}
07:08:24,064 INFO [] (MSC service thread 1-3) Stopped deployment 07-exp1.war in 6ms
07:08:24,066 ERROR [] (DeploymentScanner-threads - 2) {"Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"07-exp1.war\".jndiDependencyService missing [ ]","\"07-exp1.war\".module.07-exp1.07-exp1.0 missing [ ]"]}}}

Jeanne Harris

Joined: May 07, 2012
Posts: 3
For a test I created a simple java project with one file called and deployed it as a Java App and it runs with no errors. I accessed the database and display the two records and three fields as expected. I am missing or have an error in my jsp projects environment somewhere.

I agree. Here's the link:
subject: Data Source Connection with MySQL
It's not a secret anymore!