JBoss4.0 configuration of the mysql data source

xiaoxiao2021-03-06  40

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: < Local-TX-DataSource> mysqlds jdbc: mysql: // localhost: 3306 / test Org.gjt.mm .mysql.driver root QWE123

mysql

3, build a Our WAR package Testds.war contains meta-inf / jbosscmp-jdbc.xml, overloaded the default data source Java: / mysqlds mysql 4, establish a servlet for testing, put it on the package 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 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

my servlet test.myservlet My Servlet / * . Start JBoss, type http: // localhost: 8080 / testds / display OK, success in your browser! ! !

转载请注明原文地址:https://www.9cbs.com/read-77761.html

New Post(0)