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="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5" >
<display-name>DataSourceExample</display-name>
<
servlet>
<display-name>DataSourceExample</display-name>
<servlet-name>DataSourceExample</servlet-name>
<jsp-file>/DataSourceExample.jsp</jsp-file>
</servlet>
<resource-ref>
<res-ref-name>jdbc/DataSourceExample</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<welcome-file-list>
<welcome-file>DataSourceExample.jsp</welcome-file>
</welcome-file-list>
</web-app>