jboss4.1配置mysql_jboss4。0下mysql数据源的配置

花了一个小时的时间,搞了一下jboss4。0下mysql数据源的配置。下面是一些具体过程

1、首先安装mysql数据库并将其驱动程序考到jboss的server\default\lib下面

2、将mysql-ds.xml文件放置到server\default\deploy下面

内容如下:

MySqlDS

jdbc:mysql://localhost:3306/test

org.gjt.mm.mysql.Driver

root

qwe123

mySQL

3、建立一个自己的war包 testds.war

内含有META-INF/jbosscmp-jdbc.xml, 重载默认的数据源

java:/MySqlDS

mySql

4、建立一个servlet进行测试,放在上面的包中

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

/p>

PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd">

my Servlet

test.myservlet

my Servlet

/*

呵呵。启动jboss,在浏览器中键入http://localhost:8080/testds/  显示OK,成功!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值