It took an hour to figure out jboss4. Configure the mysql Data Source at 0. The following are some specific processes:
1. First install the mysql database and test its driver to serverdefalib lib of jboss.
2. Place the mysql-ds.xml file under serverdefadedeploy
The content is as follows:
<Datasources>
<Local-tx-datasource>
<Jndi-name> MySqlDS </jndi-name>
<Connection-url> jdbc: mysql: /localhost: 3306/test </connection-url>
<Driver-class> org. gjt. mm. mysql. Driver </driver-class>
<User-name> root </user-name>
<Password> qwe123 </password>
<! -- Corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<Metadata>
<Type-mapping> mySQL </type-mapping>
</Metadata>
</Local-tx-datasource>
</Datasources>
3. Create your own war package testds. war
Contains META-INF/jbosscmp-jdbc.xml, reload default data sources
<Jbosscmp-jdbc>
<Defaults>
<Datasource> java:/MySqlDS </datasource>
<Datasource-mapping> mySql </datasource-mapping>
</Defaults>
</Jbosscmp-jdbc>
4. Create a servlet for testing and put it in the package above
Package test;
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
* 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)