After spend an hour, I have made the configuration of the mysql data source in JBoss4.0. Here are some specific procedures 1, first install the mysql database and take the driver to server / default / lib under JBoss 2, place the mysql-ds.xml file to Server / Default / Deploy below:
datasources> 3, build a Our WAR package Testds.war contains meta-inf / jbosscmp-jdbc.xml, overloaded the default data source
Import java.io.ioException;
import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.sql *;. import javax.naming *;. import javax . SQL. *; Import java.io. *;
/ ** * @Author administrator * * Todo to change the Template for this generated type comment go to * window - preferences - java - code style - code templates * / public class myservlet extends httpservlet {
/ * (Non-Javadoc) * @see javax.servlet.http.HttpServlet # doGet (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) * / protected void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException , IOException {// TODO Auto-generated method stub //super.doGet(arg0, arg1); PrintWriter out = res.getWriter (); Connection conn = null; Statement stmt = null; ResultSet rs = null; try {Context initCtx = new initialcontext (); DataSource DS = (DataSource) INitctX.lookup ("java: / mysqlds"); conn = ds.getConnection (); if (conn! = null) Out.println ("OK"); else Out .println ("error");} catch (exception e) {system.out.println ("exception" e);}}} Web.xml XML Version = "1.0" encoding = "ISO-8859-1 "?>